我正在尝试逐行读取文本文件并从多行创建一行,直到读入的行末尾有 \r\n 。我的数据如下所示:
BusID|Comment1|Text\r\n
1010|"Cuautla, Inc. d/b/a 3 Margaritas VIII\n
State Lic. #40428210000 City Lic.#4042821P\n
9/26/14 9/14/14 - 9/13/15 $175.00\n
9/20/00 9/14/00 - 9/13/01 $575.00 New License"\r\n
1020|"7-Eleven Inc., dba 7-Eleven Store #20638\n
State Lic. #24111110126; City Lic. #2411111126P\n
SEND ISSUED LICENSES TO DALLAS, TX\r\n
我希望数据看起来像这样:
BusID|Comment1|Text\r\n
1010|"Cuautla, Inc. d/b/a 3 Margaritas VIII State Lic. #40428210000 City Lic.#4042821P 9/26/14 9/14/14 - 9/13/15 $175.00 9/20/00 9/14/00 - 9/13/01 $575.00 New License"\r\n
1020|"7-Eleven Inc., dba 7-Eleven Store #20638 State Lic. #24111110126; City Lic. #2411111126P SEND ISSUED LICENSES TO DALLAS, TX\r\n
我的代码是这样的:
FileStream fsFileStream = new FileStream(strInputFileName, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);
using (StreamReader srStreamRdr = new StreamReader(fsFileStream))
{
while ((strDataLine = srStreamRdr.ReadLine()) != null && !blnEndOfFile)
{
//code evaluation here
}
我努力了:
if (strDataLine.EndsWith(Environment.NewLine))
{
blnEndOfLine = true;
}
和
if (strDataLine.Contains(Environment.NewLine))
{
blnEndOfLine = true;
}
这些在字符串变量的末尾看不到任何内容。有没有办法告诉我真正的行尾,以便我可以将这些行组合成一行?我应该以不同的方式阅读文件吗?