[Help] Manipulating data from text file
Hello guys.
I'm trying to manipulate the data from a txt file generated by a third party program. Here is basically the content of the file: http://pastebin.com/raw/gg15s10e
I think I can make some use of the StreamReader, maybe pass each line to an array and then turn the data into a CSV file.
I'm thinking basically in something like this: get the line, if the characters 1 to 19 contains "Name." then get the characters 20 to 83 and store in the variable name. Then I make the "right side column" of the txt file using the same logic to get the code, move to next line and so on.
Is that possible? Thats the approach? Since I'm still learning C# (my 1st language) I don't know if this is the best way to do that. Can you guys point me C# methods I can use here? Thank you.
Posted Nov 30, 2016, 2:08 PM UTC · edited
That looks like a rather annoying format to parse consistently. You could get about 90% of the way with a simple regex, but then there are a bunch of exceptions like the "STATE" field in the middle of nowhere and the ADR lines.
Hardcoding the positions of the values like you suggested would be a possible option, but it would also be error-prone to maintain and set up.
What happens to overlong values? Is there a possibility of multi-line values being entered?
No they can't be multi-lines.