Results 1 to 5 of 5

Thread: Have extra time? I NEED help!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353

    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:
    1. Function LastName(ByVal WholeName As String) As String
    2.         Dim arr() As String
    3.         Dim LName, index As String
    4.  
    5.         WholeName = Replace(WholeName, ",", " ")
    6.         arr = Split(WholeName, " ")
    7.  
    8.         index = WholeName.IndexOf(" ")
    9.         If index = -1 Then
    10.             LName = ""
    11.         Else
    12.             If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then
    13.                 Try
    14.                     LName = arr(0) + " " + arr(1)
    15.                 Catch ex As Exception
    16.                     LName = ""
    17.                 End Try
    18.             Else
    19.                 Try
    20.                     LName = arr(0)
    21.                 Catch ex As Exception
    22.                     LName = ""
    23.                 End Try
    24.             End If
    25.         End If
    26.         Return Trim(LName)
    27.  
    28.     End Function
    29.  
    30.     Function FirstName(ByVal WholeName As String) As String
    31.         Dim arr() As String
    32.         Dim FName As String
    33.         Dim index As Integer
    34.  
    35.         WholeName = Replace(WholeName, ",", " ")
    36.         arr = Split(WholeName, " ")
    37.  
    38.         index = WholeName.IndexOf(" ")
    39.         If index = -1 Then
    40.             FName = ""
    41.         Else
    42.             If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then
    43.                 Try
    44.                     FName = arr(2)
    45.                 Catch ex As Exception
    46.                     FName = ""
    47.                 End Try
    48.             Else
    49.                 Try
    50.                     FName = arr(1)
    51.                 Catch ex As Exception
    52.                     FName = ""
    53.                 End Try
    54.             End If
    55.         End If
    56.         Return Trim(FName)
    57.  
    58.     End Function
    59.  
    60.     Function MiddleName(ByVal WholeName As String) As String
    61.  
    62.         Dim arr() As String
    63.         Dim MName, index As String
    64.  
    65.         WholeName = Replace(WholeName, ",", " ")
    66.         arr = Split(WholeName, " ")
    67.  
    68.         index = WholeName.IndexOf(" ")
    69.         If index = -1 Then
    70.             MName = ""
    71.         Else
    72.             If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then
    73.                 Try
    74.                     MName = " " + arr(3)
    75.                 Catch ex As Exception
    76.                     MName = ""
    77.                 End Try
    78.             Else
    79.                 Try
    80.                     MName = " " + arr(2)
    81.                 Catch ex As Exception
    82.                     MName = ""
    83.                 End Try
    84.             End If
    85.         End If
    86.         Return MName
    87.  
    88.     End Function

    PLEASE HELP! Thanks!

    Brenda

  2. #2
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    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

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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.

  4. #4
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    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:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.       Dim s() As String = {"Jones, Jeffrey S", "Means Marilyn", "Lawson Jay D", _
    3.          "Lopez, Manuel B.", "Lowe Jr Sam D", "Smith III Trevor L"}
    4.       Dim s2, s3 As String
    5.       For Each s2 In s
    6.          Dim s4() As String = parseName(s2)
    7.          s3 &= (s4(0) & s4(1) & s4(2)) & Constants.vbCrLf
    8.       Next
    9.       MessageBox.Show(s3)
    10.    End Sub
    11.  
    12.    Function parseName(ByVal s As String) As String()
    13.       Dim re As New Regex("(?<lname>[^""]+((\,\s)|\s|((Jr|III)\s)))(?<fname>[^""]+\s)(?<mname>[^""]+)")
    14.       Dim ma As Match = re.Match(s)
    15.       Dim s2() As String = {ma.Groups("fname").Value, ma.Groups("mname").Value, ma.Groups("lname").Value}
    16.       s2(1) = Regex.Replace(s2(1), "(\.|\,\s)", "")
    17.       s2(1) &= ". "
    18.       s2(2) = Regex.Replace(s2(2), ",", "")
    19.       Return s2
    20.    End Function

  5. #5
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843
    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.
    Merry Christmas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width