Syntax for removing spaces

If you want to extract a single letter from a word you can use "SubString". If you want to remove blank spaces then you can use "Trim"
 
Trim will do the trick

Visual Basic:
Dim myString as String = "     Your Name Here     "
myString = Trim(myString)
 
Or, yet another option, split up the trimmed text into words by
using the Split method, and then access the word in an array.

Visual Basic:
Dim s As String = "  this is a test   "
Dim words() As String

words = s.Trim().Split(" "c)

Console.WriteLine(words(1)) ' Displays "is"
 
In .Net if you use the built in functions created specifically for a class, you get better performance, and its also easier.

For those of you new to .net, just and an extra STOP charcater at the end of a variable, in this case you can do

strString = strString.Replace(" ","")
 
He means the period character. In other words, use the native
functions of the String class to perform string manipulation, rather
than the old VB6 methods.

For example, instead of myString = Trim(myString) (bad), use
myString = myString.Trim()
 
Back
Top