Results 1 to 5 of 5

Thread: String Manipulation

  1. #1

    Thread Starter
    Hyperactive Member DaveR's Avatar
    Join Date
    Mar 2001
    Location
    Ireland
    Posts
    268

    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,
    DaveR

  2. #2
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    VB Code:
    1. Dim myNames() As String
    2.     Dim firstName As String
    3.     Dim secondName As String
    4.    
    5.     myNames = Split(BigName)
    6.    
    7.     firstName = myNames(0)
    8.    
    9.     Dim i As Integer
    10.     i = 1
    11.     While (i <= UBound(myNames))
    12.         secondName = secondName & myNames(i)
    13.         i = i + 1
    14.     Wend
    I haven't tested this.
    Last edited by GlenW; Mar 12th, 2002 at 09:15 AM.

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Sub Command2_Click()
    2.     Dim s As String
    3.     s = "Peet The Pimp"
    4.     MsgBox Trim(Left(s, InStr(1, s, " ")))
    5.     MsgBox Trim(Mid(s, InStr(1, s, " "), Len(s)))
    6. End Sub
    -= a peet post =-

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub String2Array()
    2.  
    3.    Dim aryTest() As String
    4.    Dim strText As String
    5.    Dim lngCount As Long
    6.    
    7.    strText = "Joe TheRagMan"
    8.    
    9.    'Create the array
    10.    aryTest = Split(strText)
    11.    
    12.    'You now have a one-dimensional zero-based array with the
    13.    'substrings as the elements
    14.       MsgBox aryTest(0)
    15.       MsgBox aryTest(1)
    16.  
    17. End Sub

  5. #5
    Addicted Member
    Join Date
    Aug 2001
    Location
    Minneapolis, MN
    Posts
    189
    Use the Split function. Here's a little sub that splits the current string at the hyphen.
    VB Code:
    1. Public Sub SplitString(OriginalString As String)
    2.  
    3. Dim A() As String
    4.  
    5.   A = Split(OriginalString, "-")
    6.   Front = A(0)
    7.   Back = A(1)
    8.  
    9. 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
  •  



Click Here to Expand Forum to Full Width