I have this string:
Dim stringToCleanUp As String = "bon;jour" Dim characterToRemove As String = ";"
I want a function who removes the ';' character like this:
Function RemoveCharacter(ByVal stringToCleanUp, ByVal characterToRemove) ... End Function
What would be the function ?
ANSWER:
Dim cleanString As String = Replace(stringToCleanUp, characterToRemove, "")
Great, Thanks!
You can also remove a specified character or substring from a string by calling the String. Replace(String, String) method and specifying an empty string (String. Empty) as the replacement. The following example removes all commas from a string.
Using 'str. replace() , we can replace a specific character. If we want to remove that specific character, replace that character with an empty string. The str. replace() method will replace all occurrences of the specific character mentioned.
Try your Remove call with Length - 2 . To remove all the whitespace characters (newlines, tabs, spaces, ...) just call TrimEnd without passing anything.
Remove(Int32, Int32) Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted.
The String
class has a Replace
method that will do that.
Dim clean as String clean = myString.Replace(",", "")
Function RemoveCharacter(ByVal stringToCleanUp, ByVal characterToRemove) ' replace the target with nothing ' Replace() returns a new String and does not modify the current one Return stringToCleanUp.Replace(characterToRemove, "") End Function
Here's more information about VB's Replace function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With