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

Text Parsing Issue 1

Status
Not open for further replies.

Trogg

IS-IT--Management
Feb 13, 2003
80
US
Hello all,

I have a field of names that may or may not contain middle names and/or initials. Field content example is as follows:

Ramsey,Jonathan David
Smith,Elizabeth

No space before or after the comma... always a space between first and middle name/initial if there is one.I am trying to extract the first name to a field by itself. The following works as long as the name contains a space in it.

FName:Trim(Mid([NameString],InStr([[NameString],",")+1,InStr([NameString]," ")-(InStr(([NameString]),",")+1)))

It fails on the names that have no space or middle name/initial and prints #Error in the field. I am assuming some IIF statement is in order here. How can I take care of both situations and is there an easier or better way than what I have so far? Thanks in advance for any help!
 
You may try this:
Trim(Mid(NameString,InStr(NameString,",")+1,InStr(NameString [!]& " "[/!]," ")-(InStr((NameString),",")+1)))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
My personal favorite: Split the name field into an array, using the comma.

Code:
aryNames = Split(NameField,",")
LName = aryNames(0)
FName = aryNames(1)

If FName actually contains a middle name too, you could split it again, (on the space), or InStr, or...
 
Oops!! Sorry, I just noticed that this is in an SQL thread. Guess that means I've got to defer to the mid/instr solutions.
 
Thanks PHV! Works perfectly! ...star for you buddy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top