C # Write objects to read txt text files

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.