How to sort text lines in a text file

Source: Internet
Author: User

The problem is that the basic requirement is to sort the file rows in a specific order.



To solve the problem, you first read all the lines of the text, analyze them, sort them, write them back to the text file. In the following example, Insus. NET is slightly rewritten to a text file, which is only output on the page.
Download a file ds.txt, which is about the same as that of other users.



Insus. NET writes an object, that is, processing each row of a text file and converting each row into an object. In the following category, TryParse () is used to determine whether a text row meets the data analysis requirements. Obtain the correct values before and after the colon (:) When the class is applied.


The following describes how to read text files, obtain all rows, and sort them:


That is to say, when the second row is output, it is changed to the third line. Similarly, when the third row is output, it is changed to the second line, and the rest are output in normal order. You can see the final implementation result.


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.