如何读取和拆分文件? [英] how to read and split from file?

查看:70
本文介绍了如何读取和拆分文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,我想读取到我的应用程序中并使用StreamReader对其进行拆分.

I have a text file that I want to read into my application and split it using a StreamReader. How can I do this?

推荐答案

嗯,那很简单.假设您正在读取多行文件,并且想要使用空格字符将其分割,则可以使用以下命令(注意,我正在用空格字符替换换行符).
Well, that''s fairly straightforward. Suppose that you are reading in a multi-line file and you want to split it using a space character, you can use the following (notice that I''m replacing newlines with a space character).
using (StreamReader sr = new StreamReader(path))
{
    string text = sr.ReadToEnd().Replace(Environment.NewLine, " ");
    string[] split = text.Split(' ');
}


这篇关于如何读取和拆分文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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