I have the following List(Of String)
defined in my program:
MyList:
1Test
2test
3
4Test
5
I would like to remove the word "Test" (regardless of capitalization) from each item in the list if it exists.
I know I can accomplish this using the following LINQ statment:
MyList = (From MyEntry As String In MyList
Select UCase(MyEntry).Replace("TEST", "")).ToList
To get the final result:
MyList:
1
2
3
4
5
Now, just for the sake of learning Linq, I wanted to try doing it using different commands (and maybe even benchmarking them just to see which could be the best / most efficient). So I wanted to try:
MyList.ForEach(Function(MyEntry As String) MyEntry = UCase(MyEntry).Replace("TEST", ""))
But it doesn't seem to update the list.
I'm assuming this is because ForEach
doesn't replace the data being iterated over, but I wanted to hear from any LINQ experts out there what your thoughts are / what you would suggest as being the nicest / most elegant solution to accomplish this.
nicest / most elegant solution
for such a simple case that requires only a singleSelect
? – I4V May 22 '13 at 20:32ForEach
would be faster and yet did not work as expected at all and I'm just trying to understand as much about this as possible.... – John Bustos May 22 '13 at 20:40