我已经搜索了这个,但我遇到的每个解决方案都涉及到regex
女巫不是我的解决方案。C#Streamreader添加新行
我的问题很简单,我希望streamreader
每次读到单词“ice”时都会添加一个新行。请记住,streamreader
正在将输入读取为1行。
我的代码如下:
using (StreamReader sr = new StreamReader(stream))
{
VarrileKeeper.s = sr.ReadToEnd();
//Console.WriteLine(VarrileKeeper.s);
if (VarrileKeeper.s.ToString().Contains("ice"))
{
//insert newline in string
}
sr.Close();
}
怎么样的词_iceland_或别的东西containig字符_ice_? – Steve
你想要*更新*文件或只读*它以这种方式? –
你不能只用'Replace'吗? 'VarrileKeeper.s = sr.ReadToEnd()。Replace(“ice”,“ice”+ Environment.NewLine);' –