我正在编写一个程序,该程序将从 AS400 获取数据,并且需要读取文本的第一行以确定文件的位置。AS400 的数据中有很多不可打印的字符。
这是我的工作代码:
//LINQ to read first line and find what I need
var lines = File.ReadAllLines(as400file);
foreach (string line in lines)
{
//Regex the AS400 garbage out of there...
string replaced = Regex.Replace(line, @"[^\u0000-\u007F]", String.Empty);
/* ^ = not
* \u0000 - \u007F is the first 127 chars of UTF-8
* So this replaces all non ascii chars with an empty string
*/
//Rest of program code
}
但是我真的只想要文件的第一行而不是每一行。我似乎想不出一种只获得第一行的方法,而且我对 linq 的经验并不丰富。任何指示或帮助?