|
-
Aug 2nd, 2004, 01:07 PM
#1
Thread Starter
Hyperactive Member
Have extra time? I NEED help!
I need a function to pick out different parts of names. I don't have a lot of time here at work. If anyone has time, I REALLY would love your help.
This is the way names can come when I read in the data:
Jones, Jeffrey S
Means Marilyn
Lawson Jay D
Lopez, Manuel B.
Lowe Jr Sam D
Smith III Trevor L
The function I have now is far from perfect. I REALLY could use your help. I was thinking of measuing the length of the variable and by what length it was, I would use a different thing. Well, this is what I have so far:
VB Code:
Function LastName(ByVal WholeName As String) As String
Dim arr() As String
Dim LName, index As String
WholeName = Replace(WholeName, ",", " ")
arr = Split(WholeName, " ")
index = WholeName.IndexOf(" ")
If index = -1 Then
LName = ""
Else
If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then
Try
LName = arr(0) + " " + arr(1)
Catch ex As Exception
LName = ""
End Try
Else
Try
LName = arr(0)
Catch ex As Exception
LName = ""
End Try
End If
End If
Return Trim(LName)
End Function
Function FirstName(ByVal WholeName As String) As String
Dim arr() As String
Dim FName As String
Dim index As Integer
WholeName = Replace(WholeName, ",", " ")
arr = Split(WholeName, " ")
index = WholeName.IndexOf(" ")
If index = -1 Then
FName = ""
Else
If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then
Try
FName = arr(2)
Catch ex As Exception
FName = ""
End Try
Else
Try
FName = arr(1)
Catch ex As Exception
FName = ""
End Try
End If
End If
Return Trim(FName)
End Function
Function MiddleName(ByVal WholeName As String) As String
Dim arr() As String
Dim MName, index As String
WholeName = Replace(WholeName, ",", " ")
arr = Split(WholeName, " ")
index = WholeName.IndexOf(" ")
If index = -1 Then
MName = ""
Else
If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then
Try
MName = " " + arr(3)
Catch ex As Exception
MName = ""
End Try
Else
Try
MName = " " + arr(2)
Catch ex As Exception
MName = ""
End Try
End If
End If
Return MName
End Function
PLEASE HELP! Thanks!
Brenda
-
Aug 2nd, 2004, 01:37 PM
#2
Frenzied Member
Brenda -
I just barely glanced at this - oh what fun!
My name will give you fits, but please allow for it -
Du Rea, Art W. Jr.
I'm used to being mangled!
You'll probably need to make a copy of your name string all in one case (all lower case?) before parsing it. That way, searching for the various pieces, especially the titles (sr., jr., iii, etc.), may be easier.
In one of the lines, you throw away the comma "," and replace it with a space - I would try to do a split on the first comma first, since it 'should' always terminate the last name field (including the suffix, which should be easily identifiable). That is more definitive than splitting on a space.
Good luck -
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Aug 2nd, 2004, 01:40 PM
#3
Frenzied Member
Don't have a solution, but I share your pain. Parsing names (and addresses) is far from 100% accurate. I've been messing with that for years and have never found anything, nor created anything that is 100% perfect.
I've resorted to attempting to parse the name, if it's easy, like SMITH, JOHN R, then show a window to the user displaying the best parse, and allow them to change.
-
Aug 2nd, 2004, 09:51 PM
#4
Fanatic Member
got this so far but kinda crappy. hehe. it doesn't get have a mname is nothing or not nothing value. hehe. i don't know how to solve this
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim s() As String = {"Jones, Jeffrey S", "Means Marilyn", "Lawson Jay D", _
"Lopez, Manuel B.", "Lowe Jr Sam D", "Smith III Trevor L"}
Dim s2, s3 As String
For Each s2 In s
Dim s4() As String = parseName(s2)
s3 &= (s4(0) & s4(1) & s4(2)) & Constants.vbCrLf
Next
MessageBox.Show(s3)
End Sub
Function parseName(ByVal s As String) As String()
Dim re As New Regex("(?<lname>[^""]+((\,\s)|\s|((Jr|III)\s)))(?<fname>[^""]+\s)(?<mname>[^""]+)")
Dim ma As Match = re.Match(s)
Dim s2() As String = {ma.Groups("fname").Value, ma.Groups("mname").Value, ma.Groups("lname").Value}
s2(1) = Regex.Replace(s2(1), "(\.|\,\s)", "")
s2(1) &= ". "
s2(2) = Regex.Replace(s2(2), ",", "")
Return s2
End Function
-
Aug 3rd, 2004, 07:17 AM
#5
Fanatic Member
There is no clean way to do this.
But as WebTest stated, you have to allow for first names to contain a space.
I would definatly attempt to split at the comma first,
if there was no comma then go with the spaces.
This is why computers have multiple fields for input
one for first,
one for last,
and middle (if needed)
This task would be a million times easier if you could attack it at the source.
haveing last,first,MI be the format and reject the others.
** I know this is kinda less-than-helpful, but you will have more troubles
down the line if you cannot split down the first,last and middle names.
especially if someone else ends up using the data in it's raw format,
they will have the same trouble you do, and could possibly use different
names for their tasks and not match to yours.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|