我在这里看到了很多帖子,但都在讲述如何逐行读取文本文件。但我不想逐行读取,我想逐行读取。
我的文本文件示例如下
Accepted, 2013/02/22, 20:12, ss123, 1234,1234,1234,Failed*Some reason ,20,500
Rejected, 2013/02/22, 20:12, ss123, 1234,1234,1234,Failed*Some reason ,20,500
输出我想要的文本文件:
Accepted, 2013/02/22, 20:12, ss123, 1234,1234,1234,Accepted,20,500
拒绝,2013/02/22, 20:12, ss123, 1234,1234,1234,Some reason ,20,500
在上面的输出示例中,首先我需要检查该行是否包含 Accepted,如果它包含 Accepted 那么我需要用 Accepted 替换第 8 列(失败*某些原因),否则我需要在第 8 列中只写原因(一些原因)为什么它被拒绝......如果你能解决我的问题,请提前感谢......
我在想是否喜欢以下代码..anybuddy plz帮助我..在此处输入代码
try
{
System.IO.TextReader ReadFile = new StreamReader("c:\\ATMLOG.txt");
System.IO.TextWriter writeFile = new StreamWriter("c:\\DeatailReport.txt");
string line = ReadFile.ReadLine()
while(line!=null)
{
if(line.contains("Accepted")
{
string[] strArr = line.Split(',');
strArr[8]="Accepted";//i wanted to replace 8th column of comma separated text file line with Accepted
TextWrite.writeln(line);
}
else
{
switch(strArr[8])
{
case "some reasson" : //which reason will be mached that should be write on 8th column of comma separated text file
case "some reasson":
;
;
;
}
}
catch (IOException ex)
{
MessageBox.Show(ex.ToString());
}