Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hif guys, i have this assignment where im supposed to extract headstone data from an inscription file(structured text files).From this file im supposed to extract the name of dead person,date of burial,date of birth (or age) and also personal message.The application should analyse a raw file and then extract information and dislay it in tabular form.The raw text file looks like this:in lovin memory of/JOHN SMITH/who died on 13.02.07/at age 40/we will miss him/in loving memory of/JANE AUSTIN/who died on 10.06.98/born 19.12.80/hope you are well in heaven. Basically "/" is a delimiter and a name is always in capital letters.i have tried using String.Split() and substring bt i cant get it to work line by line i can only get the raw data without the delimiter but i dont know how to extract specific information i really need help asap.thanks
Posted

What problem are you having specifically? If each line contains the same type of information, then you can just split each line and then split by a right slash. You can always put the strings for each line into their own list. So, you'd have a list of list of strings (that will help you keep things separate). The first string will be the first inscription, the second the name, the third the date of death, and so on. If you are having trouble extracting the date, look into regular expressions, or just use substring to extract the last few characters (the date). Then you can use DateTime.Parse to get the date into a workable format. Let us know what your specific problem is and we can help further.
 
Share this answer
 
Looks like you need to split the string two times.

First step would be to split the strings using newline feed.
This would give you a list of all the strings that will be related to one person per item with data delimited by "/"
something like:
// Split the string on line breaks.
// ... The return value from Split is a string[] array.
//
string[] lines = Regex.Split(value, "\r\n");



Now split each item using "/" as delimiter.
// Split string on /.
        // ... This will separate all the words.
        //
        string[] words = s.Split('/');


You will get all the info.
 
Share this answer
 
Use Split('/') to get the separate lines, and then for each line, use Split(' ') to break the line up into words.

At that point, you can use the TryParse() method for the desired type to retrieve data. You'll have to do additional coding to determine exactly what data you're getting (to see if an integer is an age, or what the date represents), but it's certainly not hard to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900