C#StreamReader使用分隔符保存到Array [英] C# StreamReader save to Array with separator

查看:73
本文介绍了C#StreamReader使用分隔符保存到Array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有制表符分隔数据的文本文件.在C#应用程序中,我需要从文本文件中读取一行并将其保存到数组中,并在每个 \ t 处将它们分开.然后,我对下一行执行相同的操作.

I´ve got a text file with tabulator separated data. What I need in my C# application is that I read one line from the text file and save them to an array, separate them at the each \t. Then I do the same thing with the next row.

我的代码:

StreamReader sr = new StreamReader(dlg.FileName);
string s = sr.ReadLine();

现在,我已经尝试将行写入数组,但这行不通.有人能解决这个问题吗?

Now, I already tried to write the line into an array but that doesn´t work. Does anyone one how to manage this?

推荐答案

使用Split方法创建行的数组

Use the Split method to create an Array of the line

string[] parts = s.Split('\t');

在此处查看有关Split()的文档

这篇关于C#StreamReader使用分隔符保存到Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆