CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    17

    splitting names from db

    hi

    i need help finding a solution for my problem...

    i reading names from a database field and i want to split them in 2 colums,

    For Each DR In DT.Rows
    sString = DR.Item("Customer")
    Dim Name() As String = sString.Split(" ")
    MsgBox(Name(0))
    Next

    works fine for names like smith john, with 2 words but suppose a name has 3 words like Van hagen John, you have 2 spaces. is their a way to see the last space so you can filter out the prename ?

    tnx in advance

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: splitting names from db

    First suggestion would be to normalize your database. Second would be to use SubString() and IndexOf Methods to split up the string on the last space.

  3. #3
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    17

    Re: splitting names from db

    i can't really see how you can do that with those functions ? :s

    can u give me an example pls?

    Tnx

  4. #4
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: splitting names from db

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Name As String = "Van Hagen John"
    Dim First As String = Name.Substring(Name.LastIndexOf(" "))
    Dim Last As String = Name.Substring(0, Name.LastIndexOf(" "))
    MsgBox(First & "-" & Last)
    End Sub

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

Featured