views:

97

answers:

3

Hie guys i have this assignment where im supposed to extract headstone data from an inscription file (structured text file).From this file im supposed to extract the name of a deceased person, date of birth (or age) and also personal messages.The application should be able to analyse a raw text file and then extract information and display it in tabular form.The raw text files looks like this:

In loving memory of/JOHN SMITH/who died on 13.02.07/at age 40/we will miss you/In loving memory of/JANE AUSTIN/who died on 10.06.98/born on 19.12.80/hope you are well in heaven.

Basically "/" is a delimiter and the name of a deceased person is always in capital letters. I have tried to use String.Split() and substring methods but i cant get it to work for me; I can only get raw data without the delimiter (Environment.Newline) but i dont know how to extract specific information.

+1  A: 

You'll need something like:

  • Open your data file (System.IO)
  • For each line, do (tip: pick a stream where you can read line by line)
    • Split them by "/" getting a string[]
    • Arrays in C# starts at 0; so splitted[1] will be that name, ans so on
    • Store that information in a managed collection (maybe to use generics?)
  • Display that collection in a tabular view
Rubens Farias
A: 

Check out How to: Use Regular Expressions to Extract Data Fields. I know the example is in C++, but the Regex and Match classes should help you get started

Here is another good example of parsing out individual sentences.

SwDevMan81
A: 

I would have thought something like this would do the trick

 private static void GetHeadStoneData()
 {
    using(StreamReader read = new StreamReader("YourFile.txt"))
    {
       const char Delimter = '/';
       string data;
       while((data = read.ReadLine()) != null)
       {
            string[] headStoneInformation = data.Split(Delimter);
            //Do your stuff here, e.g. Console.WriteLine("{0}", headStoneInformation[0]);
       }
    }
 }
Michael Ciba
@Michael, that's homework..
Rubens Farias