从列表中删除具有相同值的索引的分割线
问题描述:
- 从列表中例如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 ++项。
谢谢
答
好,我得到了答案,这是工作
项目= 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
}
}
}
这是你遇到问题或者你只是想让我们为你做吗? – Abion47
CSV到DataTable,按列区分,如果需要,再次将其保存在文件中。你的问题也太广泛了! – mybirthname
嗨@ Abion47对我来说这是一个棘手的问题,所以我要求有人可以帮助我。 –