Hi,

I am pretty new to c# presently. I have a text file called tc.txt (comman separated) with the following content below:


T001,Dirks,c:\dirks\001.tif
T001,Dirks,c:\dirks\002.tif
T002,Matt,c:\matt\003.tif
T002,Matt,c:\matt\004.tif
T003,Ted,c:\Ted\005.tif
T003,Ted.c:\Ted\006.tif

When the file is read and written to another text file called output.txt (comma seperated). every line within the same folder should be written as follow;

T001,Dirks,c:\dirks\001.tif,c:\dirks\002.tif
T002,Matt,c:\matt\003.tif,c:\matt\004.tif
T003,Ted,c:\Ted\005.tif,c:\Ted\006.tif

Any help will be appreciated.

Member Avatar for iamthwee

This is pretty straight forward string manipulation. Read each line into a buffer then, just concatenate every two lines. chop out the parts you don't need. Every two lines could be accounted for using the mod operator.

It could be better to keep lines in Dictionary<string, Collection<string>), where T001, T002 etc is key, and string with filename is a part of value collection. Advantage of this way is that it is OK if source strings are mixed up (T001, T003, again T001, T002 etc), and every T... may contain any number of lines, but not only two.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.