How do you remove spaces from a string in VB.NET?
Use the String. replace() method to remove all whitespace from a string, e.g. str. replace(/\s/g, '') . The replace() method will remove all whitespace characters by replacing them with an empty string.
The LTrim , RTrim , and Trim functions remove spaces from the ends of strings.
The Trim function removes spaces on both sides of a string. Tip: Also look at the LTrim and the RTrim functions.
Trim() Removes all leading and trailing white-space characters from the current string.
To remove ALL spaces:
myString = myString.Replace(" ", "")
To remove leading and trailing spaces:
myString = myString.Trim()
Note: this removes any white space, so newlines, tabs, etc. would be removed.
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