Re: [問題] 請問如何搜尋特定資料複製輸出
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
→
04/10 14:56, , 1F
04/10 14:56, 1F
→
04/10 14:56, , 2F
04/10 14:56, 2F
討論串 (同標題文章)
完整討論串 (本文為第 7 之 7 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章