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!
Re: Splitting a name Function...help!
Quote:
Originally posted by brendalisalowe
VB Code:
Function SplitName(ByVal WholeName As String) as String 'add return type
Dim arr() As String
Dim FirstName As String
Dim LastName As String
WholeName = Replace(WholeName, ",", " ")
arr = Split(WholeName, " ")
LastName = arr(0)
FirstName = arr(1)
'remove any comma in first name
If FirstName.EndsWith(",") Then
FirstName = FirstName.SubString(0, FirstName.Length - 1)
Return Firstname & " " & LastName 'return
End Function