vb.net - searching a list object -
I have a list:
Dim list as new string
Blockquote>
What is an easy and fast way to find duplicates of "first block" plus "-" plus "second block" is already on the list. Example 290-7 items are displayed twice, 290-7-11 and 290-7-13.
I am using .NET 2.0
If you only want to know Whether there are any duplicates but do not care what they are ...
The easiest way (assuming two dashes).
Boolean headplicet profiles = list .GroupBy (i => i.Substring (0, i.LastIndexOf ('-')) Anyone (g = & gt; g.Count ( ) & Gt; 1)
Fastest method (for a large set of smallest strings).
Hasheset & lt; string & gt; HashSet = New HashSet (); Boolean HeadplicetPfix = False; Forex (String Item in List) {String Prefix = Item. Tilting (0; Item. Last Index ('-')); HashSetConton (Prefix) {HeduplicatePf If there are more than two dashed cases, then use the following: it still with a single dash. Will be unsuccessful. string prefix = items. Substring (0, item.InexexOf ('-', item.InexexOf ('-') + 1));
instead of
Lt; string, boolean & gt; dictionary = new dictionary & lt; string, boolean & gt; (); boolean headplicet profile = false; Forex currency (string item in the list) {string prefix = item Inclination (0, item. Last index ('-')); If (dictionary) of prefix. {Heduclicate = true; break; } Else {dictionary.Add (prefix, true); }}
If you do not care about readability and speed, then use an array instead of the list, and you the real fan of regular expressions , Then you
Boolean hasiflicate profiles = Regex.IsMatch (String.Join ("#", list), @ ". * * (?: ^ | #) ([0- 9] + - [0-9] + -) * # 1 ") .;
Comments
Post a Comment