Reputation: 41
I need to extract headstone data from an inscription file (structured text file). From this file I am 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 can't get it to work for me; I can only get raw data without the delimiter (Environment.Newline
) but I don't know how to extract specific information.
Upvotes: 1
Views: 242
Reputation: 561
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]);
}
}
}
Upvotes: 0
Reputation: 49978
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.
Upvotes: 0
Reputation: 57946
You'll need something like:
System.IO
)string[]
Upvotes: 2