I have this function, which works and gives the correct result:
<System.Runtime.CompilerServices.Extension()>
Public Function Unique(List As List(Of String)) As List(Of String)
Return List.Select(Function(x, index) x & System.Text.RegularExpressions.Regex.Replace((List.GetRange(0, index).Where(Function(y) y = x).Count + 1).ToString, "\b1\b", String.Empty)).ToList
End Function
This function appends a "2", "3", etc as needed, to those items that are not unique, to make them unique.
How can I remove the regex while a) staying in the same linq statement (the same line of code), b) without introducing a loop or c) evaluating the expression twice, as would be needed in an IIF
statement?
This is not a duplicate of Getting index of duplicate items in a list in c#, because a) my list does not change during the function and b) that question was not answered with a ready to apply code example, and here I'm looking for a specific fix to a specific line of code. Those answers will not fix my issue; they do not apply here.