Reads the specified columns in a text file and the columns in the text file.

Source: Internet
Author: User

Reads the specified columns in a text file and the columns in the text file.

I saw a problem on the forum today. This is probably the case. I read the specified columns in the text file and store them in the database.

Insus. NET takes less time to read text.
Create a text file and add several lines of text. Each row has several columns separated by commas.

adf,adfadf,adsfgads,qwer,wrt,wrey,asdfs,qwer,tryerqert6uy7,468u4,578,qewrqew,qwertwet,67u46,45676,45qer87,47857,et356y,etyedghadsadf,adfadf,adsfgads,qwer,wrt,wrey,asdfs,qwer,tryert6uy7,468u4,5ZXC78,qewrqew,qwertrtwet,67u46,456qer76,4wu1587,47wr857,etyty,etyedghadwrf,adfadf,adsfgads,qwuier,wrqert,wrey,aswrtdfs,qwer,try790ert6uy7,468u4,572458,qewrqew,qwertwet,67u46,45676,4rwt587,47857,etuoipy,etyedghad356f,adf1324adf,adsfgads,qwasdfer,wrt,wrey,asdfs,qwer,tryert6uy7,468u4,5rt78,qewrqew,qwertwetyet,67u46,45676,4zcxv587,47857,ety,etyedghadf356,adfadf,adsfga34ds,qwer,wrt,wrey,asdfs,qwer,tryert6uy7,468u4,578,qewwtrrqew,qwerqertwet,67u4ety6,45676,4587,47857,etwey,etyedghad869f,adfeadf,adsfqrgads,qwer,wrt,wrey,as689dfs,qwer,trytyert6uy7,468u4,578,qewrqew,qweroyiotwet,67u46,45676,4535687,47857,ety,etyedgh


If you want to use this example for demonstration, you can save it as a. txt file.

Next, we can implement this. No matter whether a text file has a column name, you are not concerned about the column name of the data table.
Write a model as a data table, for example:

 

In this category, you can see an interpreted function: TryParase (); it processes text data rows. Read the first 10 columns of each text file. Of course, you can change the number of columns to be read.
Also, check whether there are blank lines and spaces at the beginning and end of each line of text. Whether the number of columns is sufficient and whether there are other rule separator characters.


Then you can use this number and function in the program:



In the code, Insus. NET displays the obtained data in the GridView control, omitting the function of storing data in the database.

Finally, the result is displayed:



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.