|
-
Jun 23rd, 2004, 12:55 PM
#1
Thread Starter
Hyperactive Member
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!
-
Jun 23rd, 2004, 01:03 PM
#2
Frenzied Member
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.
-
Jun 23rd, 2004, 01:08 PM
#3
Frenzied Member
Re: Splitting a name Function...help!
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
Last edited by salvelinus; Jun 23rd, 2004 at 01:15 PM.
-
Jun 23rd, 2004, 01:08 PM
#4
Hyperactive Member
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
-
Jun 24th, 2004, 01:21 AM
#5
Fanatic Member
i have this
VB Code:
Module Module1
Sub Main()
Dim s() As String = brown_monkey_splitting("brown monkey is in the move.")
Console.WriteLine(s(0))
End Sub
Function brown_monkey_splitting(ByVal s As String) As String()
Return (Split(s, " "))
End Function
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|