|
-
Mar 12th, 2002, 08:58 AM
#1
Thread Starter
Hyperactive Member
String Manipulation
Hello,
I have a database of names , and I want to split them into first and last names.
My criteria , is that everything before the first space will be the firstname and the remainder will be the lastname.
Can someone direct me which string manipulation functions i should be using.
Thanks,
-
Mar 12th, 2002, 09:06 AM
#2
Hyperactive Member
VB Code:
Dim myNames() As String
Dim firstName As String
Dim secondName As String
myNames = Split(BigName)
firstName = myNames(0)
Dim i As Integer
i = 1
While (i <= UBound(myNames))
secondName = secondName & myNames(i)
i = i + 1
Wend
I haven't tested this.
Last edited by GlenW; Mar 12th, 2002 at 09:15 AM.
-
Mar 12th, 2002, 09:07 AM
#3
-= B u g S l a y e r =-
VB Code:
Private Sub Command2_Click()
Dim s As String
s = "Peet The Pimp"
MsgBox Trim(Left(s, InStr(1, s, " ")))
MsgBox Trim(Mid(s, InStr(1, s, " "), Len(s)))
End Sub
-
Mar 12th, 2002, 09:07 AM
#4
VB Code:
Private Sub String2Array()
Dim aryTest() As String
Dim strText As String
Dim lngCount As Long
strText = "Joe TheRagMan"
'Create the array
aryTest = Split(strText)
'You now have a one-dimensional zero-based array with the
'substrings as the elements
MsgBox aryTest(0)
MsgBox aryTest(1)
End Sub
-
Mar 12th, 2002, 09:13 AM
#5
Addicted Member
Use the Split function. Here's a little sub that splits the current string at the hyphen.
VB Code:
Public Sub SplitString(OriginalString As String)
Dim A() As String
A = Split(OriginalString, "-")
Front = A(0)
Back = A(1)
End Sub
Oh darn, my browser must have been cached or something. After I typed this up, I see there was already replies. Oh well, here ya go anyway!
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
|