|
Ahhh, it looks like you need more than just getting rid of spaces.
Here's some pseudo code for you.
StateEngine = 1
Namestring = Trim(Name)
Title = "", FirstName = "", MiddleName = "", LastName = "", Suffix = "", Extra
= ""
While Length(Namestring <> 0)
Pos = Locate(" ", Namestring)
ThisPart = Left(Namestring, Pos - 1)
ThisPartLength = Length(ThisPart)
If Right(ThisPart, 1) = "."
ThisPart = Left(ThisPart, Length(ThisPart) - 1)
EndIf
If StateEngine = 1
If Upper(ThisPart) = "DR" Or Upper(ThisPart) = "MR" or Upper(ThisPart) =
"MRS" or
Upper(ThisPart) = "MS" or Upper(ThisPart) = "MISS".....
Title = ThisPart
ThisPart = ""
StateEngine = 4 ' First Name should be next, we are in Last, first
format
EndIf
If ThisPart <> "" And Right(ThisPart, 1) = ","
LastName = ThisPart
ThisPart = ""
StateEngine = 2 ' First Name should be next
EndIf
If ThisPart <> "" And StateEngine = 1 Or StateEngine = 2 Or StateEngine = 4
FirstName = ThisPart
ThisPart = ""
if StateEngine = 4
StateEngine = 5 ' Middle name/initial should be next, in Last, First
format
Else
StateEngine = 3 ' Middle name/initial or lastname should be next
EndIf
EndIf
If ThisPart <> "" And StateEngine = 3 or StateEngine = 5
If LastName = ""
LastName = ThisPart
Else
If StateEngine = 5
If Upper(ThisPart) = "JR" Or Upper(ThisPart) = "SR" or
Upper(ThisPart) = "DDS" or
Upper(ThisPart) = "MD" or Upper(ThisPart) = "ESQ".....
Suffix = ThisPart
ThisPart = ""
StateEngine = 7 ' We should be done, don't know what to do with
next stuff
Else
If MiddleName = ""
MiddleName = ThisPart
StateEngine = 6 ' We could have a suffix next
Etc.. etc.. etc...
NameString = Trim(Right(NameString, Length(NameString) -
Length(ThisPartLength)
End While
Basically, what you wind up then is fields FirstName, Middle Name, Last Name,
Title, Suffix and Extra that can either have data or be blank, and are usually
80% right. You then print them out, or display on screen, next to the original
text and browse through them looking for the exceptions.
I had to do something like this once. Parsing free form text is not always
easy. Using the State Engine makes it simpler.
Good Luck.
Regards,
Jim Langston
-----Original Message-----
From: Joel Fritz [mailto:JFritz@sharperimage.com]
One way first and last names get concatenated is mailing lists. Often the
record is more useful with one name field that contains the name in the form
that it should appear on the mailing label. Parsing whole name fields into
their components is not a simple task. Consider "Dr Elvis A. de Presley
Jr".
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.