问题描述
{"a,23sd44","a,23s5sf4","bb,sd2364","a,2f534","bb,2sfds434"}数组求去除重复(只考虑逗号前)保留最后出现的。结果{"a,2f534","bb,2sfds434"}重点,逗号之后的不考虑,保留最后出现的不是第一次出现的值
解决方案
解决方案二:
百度了一个数组处理的方法,可以去除重复但是保留的是第一次出现的数据,我需要保留最后出现的数据。听人说用字典树但是不知道是什么
解决方案三:
就是Directory啊,每次插入新值前判断键值是否存在PrivateDeviceCollectionAsnewDictionary(OfString,String)IfNotDeviceCollection.ContainsKey("a")ThenDeviceCollection.Add("a",value)elseDeviceCollection.Item("a").value=valueendif
解决方案四:
打错了,是DictionarydimvalueasstringDeviceCollection.Item("a")=value
解决方案五:
string[]arr={"a,23sd44","a,23s5sf4","bb,sd2364","a,2f534","bb,2sfds434"};foreach(varstrinarr.GroupBy(s=>s.Split(',')[0]).Select(g=>g.Last())){Console.WriteLine(str);}
解决方案六:
解决方案七:
string[]arr={"a,23sd44","a,23s5sf4","bb,sd2364","a,2f534","bb,2sfds434"};System.Collections.Hashtableht=newSystem.Collections.Hashtable();for(inti=0;i<arr.Length;i++){ht[(arr[i].Split(','))[0]]=arr[i];}
解决方案八:
解决方案九:
Subtest()DimdicAsNewDictionary(OfString,String)Dimarr()AsString={"a,23sd44","a,23s5sf4","bb,sd2364","a,2f534","bb,2sfds434"}ForiAsInteger=0ToUBound(arr)dic(Split(arr(i),",")(0))=arr(i)NextDimbrr()AsString=dic.Values.ToArrayMsgBox(Join(brr,","))EndSub