Re: [問題] 請問如何搜尋特定資料複製輸出

看板C_Sharp (C#)作者 ( )時間12年前 (2013/04/10 14:27), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串7/7 (看更多)
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
感謝O2000版友幫忙 將if()裡 改成foris.Count!=0
04/10 14:56, 1F

04/10 14:56, , 2F
就可以正常跑了 謝謝
04/10 14:56, 2F
文章代碼(AID): #1HPGPjSG (C_Sharp)
文章代碼(AID): #1HPGPjSG (C_Sharp)