2016-10-04 67 views
-2

- 從列表中例如9120038560640發生兩次或可能超過該次數。存儲在列表< .string
-lines>項= File.ReadAllLines(文件路徑).ToList();
- 每條線分成分號。
- 第二個索引或[1]應與所有行進行比較,並刪除找到的匹配項。
從列表中刪除具有相同值的索引的分割線

363193; 9120038560640; 7,11; 9,99 < ----必須除去
363195; 9120038560641; 9,81; 14,99
363194; 9120038560640; 9,81; 14,99 < ---必須除去
363196; 9120038560642; 9,81; 14,99
363197; 9120038560643; 9,81; 14,99
....
..

BTW。我的文件有25,000 ++項。
謝謝

+2

這是你遇到問題或者你只是想讓我們爲你做嗎? – Abion47

+0

CSV到DataTable,按列區分,如果需要,再次將其保存在文件中。你的問題也太廣泛了! – mybirthname

+0

嗨@ Abion47對我來說這是一個棘手的問題,所以我要求有人可以幫助我。 –

回答

0

好,我得到了答案,這是工作

項目= items.Where(X => x.Split( ';'!)[columnIndex] = 「」).OrderBy(X => x.Split(';')[columnIndex])。ToList(); List < .string> _items = items.ConvertAll(z => z); //我做獨立副本

 string[] itemsArr = items.ToArray(); 
     int countA = 0; 
     foreach (string itemArr in itemsArr) 
     { 
      List<int> groupDuplicates = new List<int>(); 
      for (int a = countA; a < itemsArr.Count(); a++) 
      { 
       if (itemArr != itemsArr[a]) 
       { 
        if (itemArr.Split(';')[columnIndex] == itemsArr[a].Split(';')[columnIndex]) //if matched then add 
        { 
         groupDuplicates.Add(a); // listing index to be remove 
        } 

        else 
         break; //no way to go through the bottom of the list and also to make the performance faster 
       } 
       countA++; 
      } 

      if (groupDuplicates.Count() != 0) 
      { 
       groupDuplicates.Add(groupDuplicates.First() - 1); //I add here the first item in duplicates 

       foreach (int m in groupDuplicates) 
       { 
        _items.Remove(items.ElementAt(m)); //remove by item not by index 
       } 
      } 
     } 
相關問題