Using VB.Net I'd like to be able to replace a range of characters in a string in a single line of code.
i.e. something like
Dim charsToReplace as string = "acegi"
Dim stringToBeReplaced as string = "abcdefghijklmnop"
charsToReplace.ToArray().ForEach(Function (c) stringTobeReplaced = stringTobeReplaced.Replace(c, ""))
however, this doesn't work.
the following does work, however I don't want the string to be a class level variable:
Sub Main()
Dim toReplace As String = "acegikmoq"
Console.WriteLine(mainString)
Dim chars As List(Of Char) = toReplace.ToList()
chars.ForEach(AddressOf replaceVal)
Console.WriteLine(mainString)
Console.ReadLine()
End Sub
Dim mainString As String = "this is my string that has values in it that I am going to quickly replace all of..."
Sub replaceVal(ByVal c As Char)
mainString = mainString.Replace(c, "")
End Sub
Can this be done?