2016-10-04 6 views
-2

リストから例は9120038560640が2回発生するかそれ以上である可能性があります。
リストに格納されている行< .string> items = File.ReadAllLines(filepath).ToList();
- すべての行はセミコロンで分割されています。
- 2番目のインデックスまたは[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 to DataTable、列で区別、必要に応じて再度ファイルに保存します。また、あなたの質問は広すぎます! – mybirthname

+0

こんにちは@Abion47これは私にとってはやや難しい問題ですから、誰かが私を助けてくれることを頼んでいます。 –

答えて

0

私は答えを持って、これは

項目= items.Where(X => x.Split( ';'!)[columnIndexに] = "")取り組んでいる大丈夫.OrderBy(Xを=> x.Split( ';')[columnIndex])。ToList(); リスト< .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 
       } 
      } 
     } 
関連する問題