Click to See Complete Forum and Search --> : splitting names from db


GeertL
January 24th, 2005, 03:06 PM
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

DSJ
January 24th, 2005, 04:21 PM
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.

GeertL
January 25th, 2005, 11:19 AM
i can't really see how you can do that with those functions ? :s

can u give me an example pls?

Tnx

DSJ
January 25th, 2005, 04:46 PM
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