Space removal

andycharger

Well-known member
Joined
Apr 2, 2003
Messages
152
Hi.
Im trying to trim spaces out of my Users names when I retrieve them from my SQL Server Database. Basically, I am pulling the first name and last name out and sticking them into a variable.

The problem is that If im called "Joe Bloggs" It is retrieving "Joe " and "Bloggs " making me "Joe Bloggs "
So I tried removing the spaces using Trim and Replace commands but neither seem to work. Can anyone help me with an alternative?

Here is my code:

Code:
strFName = oReader7("FirstName")
Replace(strFName, " ", "")
strLName = oReader7("LastName"
Replace(strLName, " ", "")
strName = strFName & " " & strLName

Cheers
 
Its putting spaces in but......

this forum seems to have ignored the spaces when I entered it!!!
There are about 20 trailing spaces after both my first name and last name when I retrieve it!
 
The Replace method would work if you assinged the result back to your variable.
But, you should not use the old VB6 functions. String object provides better alternatives. It also has a Replace method.
Code:
Dim spaces As String = "SOME TEXT        SOME TEXT             SOME TEXT"
spaces = spaces.Replace(" ", "")
 
Back
Top