469,271 Members | 1,787 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

way to remove empty spaces from string

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
--
Paul G
Software engineer.
Nov 21 '05 #1
6 22622

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" wrote:
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
--
Paul G
Software engineer.

Nov 21 '05 #2
temparray = array.Replace(" ", "") seemed to do the trick.

"Paul" wrote:
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
--
Paul G
Software engineer.

Nov 21 '05 #3

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
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
--
Paul G
Software engineer.


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

myString = myString.Replace(" ", String.Empty)
Mythran
Nov 21 '05 #4
ok thanks for the information.

"Joseph MCP" wrote:

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" wrote:
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
--
Paul G
Software engineer.

Nov 21 '05 #5
* "=?Utf-8?B?UGF1bA==?=" <Pa**@discussions.microsoft.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
ok thanks for the additional information.

"Herfried K. Wagner [MVP]" wrote:
* "=?Utf-8?B?UGF1bA==?=" <Pa**@discussions.microsoft.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by ted | last post: by
6 posts views Thread by Charlie | last post: by
5 posts views Thread by LEM | last post: by
36 posts views Thread by laredotornado | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.