471,887 Members | 778 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

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 22731

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
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.