如何读取特定的行分隔符的文本文件? [英] How to read text file by particular line separator character?
本文介绍了如何读取特定的行分隔符的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
阅读的文本文件中使用的StreamReader。
使用(StreamReader的SR =新的StreamReader(文件名,Encoding.Default))
{
串线= sr.ReadLine();
}
我想迫使该行分隔符应 \ñ
不是 \ r
。那么,如何能做到这一点?
解决方案
字符串文本= sr.ReadToEnd();
字符串[]行= text.Split('\ r');
的foreach(字符串s的线)
{
// 消耗
}
Reading a text file using streamreader.
using (StreamReader sr = new StreamReader(FileName, Encoding.Default))
{
string line = sr.ReadLine();
}
I want to force that line delimiter should be \n
not \r
. So how can i do that?
解决方案
string text = sr.ReadToEnd();
string[] lines = text.Split('\r');
foreach(string s in lines)
{
// Consume
}
这篇关于如何读取特定的行分隔符的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文