数据由文本文件中的C#中的列分隔

问题描述 投票:1回答:1

File txt

我在文本中有这个文件,需要在表格中组织排序。 OBS:需要是控制台应用程序c#

我这样做了:

        StreamReader sr = new StreamReader(@"filepatch.txt");
        string ler = sr.ReadLine();
        string linha = ";";
        int cont = 0;


        while((linha = sr.ReadLine())!= null)
        {

            string col = linha.Split(';')[2];
            cont++;
            Console.WriteLine("{0} : {1}", cont, linha);

        }           
c# console-application tabular
1个回答
0
投票

试试这个来获取文件文本:

var lines = System.IO.File.ReadAllLines(@"filepatch.txt");

然后你可以使用返回的string[]来执行其余的逻辑。

foreach(var line in lines)
{
    string[] cols = line.Split(';');
    // Your logic here.  
}

干杯!

© www.soinside.com 2019 - 2024. All rights reserved.