Furqan Sehgal
Furqan Sehgal

Reputation: 4997

Removing all spaces in a string

Is there any function in vb.net that removes all spaces in a string. I mean a string like ' What is this' should be 'Whatisthis'

Thanks Furqan

Upvotes: 3

Views: 27172

Answers (4)

Albert Monteiro
Albert Monteiro

Reputation: 21

I have used str=str.Replace("&nbsp","") with great success.

However, str=str.Replace(" ","") has not worked for me in the past.

Upvotes: 2

Brandon Montgomery
Brandon Montgomery

Reputation: 6986

You could use String.Replace:

Dim str As String = " What is this"
str = str.Replace(" ", "")

Upvotes: 2

user225312
user225312

Reputation: 131597

Using String.Replace:

Dim Test As String = "Hello Hi"
Test = Test.Replace(" ", String.Empty)

Upvotes: 1

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262919

Use String.Replace()

Dim s As String = " What is this"
s = s.Replace(" ", "")

Upvotes: 10

Related Questions