Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove spaces from a string in VB.NET

Tags:

vb.net

How do you remove spaces from a string in VB.NET?

like image 838
Alex Gordon Avatar asked Oct 29 '09 18:10

Alex Gordon


People also ask

How do you remove spaces from a string?

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.

How do you remove leading and trailing spaces in VB net?

The LTrim , RTrim , and Trim functions remove spaces from the ends of strings.

What is Trim in VB net?

The Trim function removes spaces on both sides of a string. Tip: Also look at the LTrim and the RTrim functions.

What .NET function can you use on a string to remove trailing spaces?

Trim() Removes all leading and trailing white-space characters from the current string.


1 Answers

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.

like image 79
David Avatar answered Oct 03 '22 01:10

David