Formatting a file...

tbonejo

Member
Joined
Apr 22, 2005
Messages
9
Programming Experience
3-5
Ok. This is basically what Im aiming to get from a comma seperated value file:

It looks like this:
LineNo data1, data2, space, space
LineNo space, space, data3, data4

I want it to become:

LineNo data1, data2, space, space
space, space, data3, data4

then becomes:

LineNo data1, data2, space, space, space, space, data3, data4

And finally like this:

LineNo data1, data2, data3, data4


Any help would be appreciated on the best way to do this.

Thanks,

Tom
 
Please post each question once only and post in the most appropriate forum. The duplicate thread has been deleted.

Read you CSV in using a StreamReader and then perform whatever edits you need. It's not really pssible to provide exact code because you haven't really described what the generic situation is. The StreamReader has a ReadToEnd method to read the entire file and a ReadLine method to read a single line. You would need to parse each line using whatever criteria are appropriate and remove the bits you don't want. You can then use a StreamWriter to write the remaining text back to a file.
 
Ok, couple of questions. If I read it in like that, what would I do to separate each field by the comma? Basically I would have to loop thru 2 lines and get rid of the spaces on both and then combine them to make 1 single line with data throughout.
 
You would use the String.Split method to create a string array from your string separated on the comma. You'd have to remove the line number separately first and then remove the elements that were empty.
 
Back
Top