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

Trying to break apart a name. 1

Status
Not open for further replies.

ironhide1975

Programmer
Feb 25, 2003
451
US
I am pulling back data from a field in the database. Sometimes the FirstName field has the complete name listed as either

Mr. John P. Doe

or

Mr. John Doe

Can someone help me out with a ASP Classic script to search the variable and break apart the Prefix, First, Middle and Last name?

 
First suggestion would be to split on the space.
Code:
arrName = Split(myDBitem, " ")
So now each piece of text has its own place in the array. This will make it easy to go through. If your only options are either 4 items with a middle name or 3 items without a middle name it will be pretty easy to go through. I'm not sure what exactly you want to do with the data, so I'll just describe how it's available to you with this method.
Code:
strNamePre = arrName(0) ' Prefix
strNameFst = arrName(1) ' First Name
strNameLst = arrName(UBound(arrName)) ' Last Name
The way to handle the dynamic possibility is to realize that the last name will always be in the UBound location. But if you want to dynamically process it you could always do something like this:
Code:
intValues = UBound(arrName)
strNamePre = arrName(0) ' Prefix
strNameFst = arrName(1) ' First Name
If intValues=3 Then
   strNameMid = arrName(2) ' Middle Name
Else
   strNameMid = "" ' No Middle Name
End If
strNameLst = arrName(intValues) ' Last Name
After that your variables for prefix, first, middle, and last names are populated with the current person's information. If that record didn't include a middle name the variable for middle name will be blank to ensure you don't accidentally maintain the middle name from the last record. Hope this helps!

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top