way to remove empty spaces from string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks
 
August 9, 2004

This custom method works for both leading, trailing, and intermingling
spaces...

Private Sub RemoveSpaces()
Dim str() As String
Dim s As String = TextBox1.Text ' get the string to split
str = s.Split(" ") ' split string into array
s = String.Join("", str) ' join it with no character
TextBox1.Text = s ' redisplay string

End Sub

I have already tried this method and it works great!

Joseph MCP
 
Paul said:
Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks

Dim myString As String = "This is my string with spaces."

myString = myString.Replace(" ", String.Empty)


Mythran
 
ok thanks for the information.

Joseph MCP said:
August 9, 2004

This custom method works for both leading, trailing, and intermingling
spaces...

Private Sub RemoveSpaces()
Dim str() As String
Dim s As String = TextBox1.Text ' get the string to split
str = s.Split(" ") ' split string into array
s = String.Join("", str) ' join it with no character
TextBox1.Text = s ' redisplay string

End Sub

I have already tried this method and it works great!

Joseph MCP
 
* "=?Utf-8?B?UGF1bA==?= said:
Hi just wondering if there is an easy way to remove spaces in a string, tried
the trim method but think it is only for leading or trailing spaces.
thanks

Take a look at the string's 'Replace' method or 'Strings.Replace' and
replace the " " with a zero-length string.
 
ok thanks for the additional information.

Herfried K. Wagner said:
Take a look at the string's 'Replace' method or 'Strings.Replace' and
replace the " " with a zero-length string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top