Read txt files and combine text lines into specific formats

Source: Internet
Author: User

Some netizens asked to read some data from the txt file and then combine the data rows in a specific format. The original topic is as follows. The requirements just now were not clearly described. Later, they were completely supplemented.



Insus. NET thinks this topic can have the ability to read text pieces, so try to implement it. The method may not be the best.
First, create a class to process each line of text in a text file. Since each line of text is divided into two segments, two attributes are declared for storage. Static TryParse () is used to determine whether the text line meets the requirements. Empty rows are not processed. They are not empty rows. They must contain three spaces. Then, assign the first section to the first attribute E1, and then assign the combination of the second and third sections to the second attribute E2. Finally, write the override ToString () method again.



Next, we start to process a text file. First, we get the physical path of the text file and then read the file.
Returns an anonymous result.
Write the required lines of text into the result.
Finally, it is the output result set.



Webpage running effect:



Related Article

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.