作者ricaro ( )
看板C_Sharp
标题Re: [问题] 请问如何搜寻特定资料复制输出
时间Wed Apr 10 14:27:54 2013
List<int> foris = new List<int>();
//selected rows ->string array
for (int i = 0; i != (fistrarray.Length); i++)//i=row# in the file
{
if (fistrarray[i].Contains(peak))
{
//use List<int> get i
foris.Add(i);
//
}
//->if (arrayString...) =selected rows
}//->for int i=...-loop=rows in the file
if (foris != null)
{
//Start-a0toa3 and Int Area row#
int i1st = foris[0];
int i3rd = foris[2];
//
//write the a0toa3 and IntArea
StreamWriter selectedrows = output.AppendText();
string a0toa3 = fistrarray[i1st].Remove(1, 5);//a0toa3 data
string IntArea = fistrarray[i3rd].Substring(45, 10);//IntArea data
selectedrows.WriteLine(FiName[0] + a0toa3 + IntArea);
selectedrows.Flush();
selectedrows.Close();
//END-a0toa3 and Int Area row#
}
else
{
//Start-no data exception
StreamWriter nodata = output.AppendText();
nodata.WriteLine(FiName[0] + " data not exist");
nodata.Flush();
nodata.Close();
//END-no data exception
}
//out put-end
--------
上面的程式码是我目前的成果
在执行时遇到一个问题
就是foris这个List<int>
假如是null的话
它不会跑else{...}里面的叙述
它还是会跑if(foris!=null){...}里的叙述
然後就变成int i1st跟int i3rd都是null 接着程式就会当掉
想请问是哪里有弄错?
不然我原本预计假如foris是null(也就是档案里没有我想要的资料)
它应该要输出 "data not exist"的
感谢各位耐心看完
假如有需要再补上啥资讯请让我知道
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.22.21
1F:→ ricaro:感谢O2000版友帮忙 将if()里 改成foris.Count!=0 04/10 14:56
2F:→ ricaro:就可以正常跑了 谢谢 04/10 14:56