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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

left, mid, right function question 2

Status
Not open for further replies.

shannanl

IS-IT--Management
Apr 24, 2003
1,071
US
I am using the following to seperate words from a string. Example of the string would be "John Q Doe".

(Left(strName, InStr(strName, " ") - 1)) returns "John"
(Mid(strName, InStr(strName, " ") + 1)) returns "Q Doe"

How can I return only the "Q" without the "Doe"? In other words anything between the blank spaces?

Thanks in advance for your help.

Shannan
 
if Len(trim(Left((Mid(strName, InStr(strName, " ") + 1)),2))) = 1 then 'test for mid initial
debug.print Left((Mid(strName, InStr(strName, " ") + 1)),1)
else
debug.print (Mid(strName, InStr(strName, " ") + 1))
end if
 
I suppose you would need to modify to account for "John Q. Doe" or maybe names like O Conner without the "'". Also prefixes such as "Mr and Mrs John Q Doe". With this in mind Strongm should be along shortly and suggest that this may be a good place to use RegExp.
 
dude,

Try the split command.

If the format is first_name middle_name last_name
do this:

dim strSplit() as string
dim strStuff as string

strStuff = "John Q Public"
strsplit() = split(strstuff," ")
strsplit(0) = firstname
strsplit(1) = middlename
strsplit(2) = lastname

MJC
 
I tried the split. It worked fine except that split(1) seemed to return the space and split(2) the middle name. That was easy enough to deal with though. I appreciat the help guys.

Thanks,

Shannan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top