Results 1 to 5 of 5

Thread: Splitting a name Function...help!

  1. #1

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

    Splitting a name Function...help!

    I have the name like this: SEAL, RANDALL R or it can look like this: SEAL RANDALL R The data comes both ways. I need to split into firstname and lastname. I just want to include the middle initial with the firstname. I need help with my function to do so. This is what I have so far:

    Function SplitName(ByVal WholeName As String)
    Dim arr() As String
    Dim FirstName As String
    Dim LastName As String

    WholeName = Replace(WholeName, ",", " ")

    arr = Split(WholeName, " ")
    LastName = arr(0)
    FirstName = arr(1)
    End Function

    Please help me. How do I return LastName and FirstName also? HELP!

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    You need to pass them in by Reference or create a struct or an object to hold them, al la

    Sub SplitName(ByRef FirstName as String, ByRef LastName as String, ByVal WholeName as String)

    or do

    Public Structure Name
    Public Firstname as String
    Public LastName as String
    End Structure

    Function SplitName(ByVal WholeName as String) as Name

    return Name

    or

    Public Class Name
    Public Firstname as String
    Public LastName as String
    End Class

    Sub SplitName(Byval oName as Name, ByVal WholeName as String)
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Splitting a name Function...help!

    Originally posted by brendalisalowe
    VB Code:
    1. Function SplitName(ByVal WholeName As String) as String  'add return type
    2.         Dim arr() As String
    3.         Dim FirstName As String
    4.         Dim LastName As String
    5.  
    6.         WholeName = Replace(WholeName, ",", " ")
    7.  
    8.         arr = Split(WholeName, " ")
    9.         LastName = arr(0)
    10.         FirstName = arr(1)
    11.         'remove any comma in first name
    12.         If FirstName.EndsWith(",") Then
    13.               FirstName = FirstName.SubString(0, FirstName.Length - 1)
    14.         Return Firstname & " " & LastName    'return
    15.     End Function
    Last edited by salvelinus; Jun 23rd, 2004 at 01:15 PM.

  4. #4
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    Try this...

    Code:
     Private Function SplitName(ByVal WholeName As String)
            Dim arr() As String
            Dim FirstName As String
            Dim LastName As String
    
            arr = WholeName.Split(" ")
            LastName = arr(0)
            LastName = LastName.TrimEnd(",")
            FirstName = arr(1)
            FirstName += " " & arr(2)
            Console.WriteLine(LastName & " " & FirstName)
        End Function
    HTH

  5. #5
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    i have this
    VB Code:
    1. Module Module1
    2.  
    3.    Sub Main()
    4.       Dim s() As String = brown_monkey_splitting("brown monkey is in the move.")
    5.       Console.WriteLine(s(0))
    6.    End Sub
    7.    Function brown_monkey_splitting(ByVal s As String) As String()
    8.       Return (Split(s, " "))
    9.    End Function
    10.  
    11. End Module
    hope this helps...

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