Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a string for the first character in each word

Status
Not open for further replies.

kostrows

Technical User
Mar 26, 2002
2
US
I am having difficulty working with strings in a client side vbscript. I am trying to take a persons first, middle and last name which was taken from an input box then parse the string for their initials then combine their initials into a variable. I have been working on this for a few days and I know this is a very basic concept but I am not getting it. Any help would be appreciated.
 
The following should handle what you wrote you want without disturbing your original string. The variable username is whatever the person has entered for their first, middle, and last name. This also handles people who have more than one "middle" name. It will not check for the number of names or if spaces weren't put between first, middle, and last names. It does, however, trim off extra spaces if more than one space is used between names.

Dim onename, initials, spaceindex

onename = Trim(username)
initials = Left(onename, 1)
spaceindex = InStr(onename, " ")
Do While spaceindex > 0
onename = Right(onename, Len(onename)-spaceindex)
onename = Trim(onename)
initials = initials & Left(onename, 1)
spaceindex = InStr(onename, " ")
Loop
 
Trollacious, your code does exactly what I needed it to do. I was making this way too complex and ended up trying to write code that went all over the place. This is very easy to understand. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top