Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi.

Im trying to trim spaces out of my User's 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:

 

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

 

Cheers

Posted

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!

  • *Experts*
Posted

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.

Dim spaces As String = "SOME TEXT        SOME TEXT             SOME TEXT"
spaces = spaces.Replace(" ", "")

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...