This blog post lets you know how to write objects, how to read text files, and how to judge and get the required lines of text according to the actual conditions.
Refer to the following questions, according to the source text, some of the output format, you need to replace the "," with a space. The first line is also appended with the following child rows after each line, separated by a space.
Insus.net also refer to the requirements of users, prepare similar text file data, but expanded, add two more groups.
122207273-001,A001207273-003,A001207273-004,A001132207273-051,Q001 207273-053,Q001207273-054,Q001142207273-081,K001207273-083,K001207273-084, K001
View Code
The following implementation begins by first creating an object Sourcelinedata, which stores the first row of data, and the empty row is skipped and not processed.
Create a second object outputlinedata, customize the output format, and override the ToString () method.
The third object, ProcessData, passes in the data source, handling the combination of the first row and the other rows in each group.
The fourth object, Readtxtfile, is to read a text file:
Finally, the data we get is the list<outputlinedata> dataset. Now we're trying to output the results to the screen:
Output Result:
C # Write objects to read txt text files