我必须在 C# 中编写一个脚本才能从文件中删除“LF”。
文件结构如下:
line1 'CR''LF'
line2 'CR''LF'
line3 'LF'
some_text_of_line_3 'CR''LF'
我想要这个:
line1 'CR'
line2 'CR'
line3 some_text_of_line_3 'CR'
谢谢 !
如果文件不是那么大(即我们可以将其读入内存):
using System.IO;
...
String path = @"c:\MyFile.txt";
// Read file, remove LF (which is "\n")
string text = File.ReadAllText(path).Replace("\n", "");
// Write text back
File.WriteAllText(path, text);
您可以尝试为此使用正则表达式:
string myFile= File.ReadAllText(@"c:\FileName.txt");
myFile= Regex.Replace(myFile, @"LF", "AnythingYouwantHere");
File.WriteAllText(@"c:\FileName.txt", myFile);
希望这对您有所帮助。