Splitting a string

I have a textbox as and input field for a SQL database search. If the user inputs a full name (first, "space", last name) I want to split this string into two values. Is there an easy way to do this

I have a string.isindex searching for a space and if there is then I need to split the two values into two different variables.

Thanks for the information.



Answer this question

Splitting a string

  • Edward1

    try the string split function:

    dim theSplitSeperator() as Char = { ' ' }

    dim theStringSplit() as string = theInputString.Split(theSplitSeperator)



  • Ggoogle

    You can use string's Split() method, like in:

    Dim parts() As String = TextBox1.Text.Split(New Char() {" "c})

    If there isn't any spaces in the textbox's text, the returned array will only contain one item. And if you need to split the string at the first space only, use:

    Dim parts() As String = TextBox1.Text.Split(New Char() {" "c}, 2)

    The second parameter will instruct the function to return two items maximum.

    Andrej



  • GrayMatter Software

    This works perfectly! Thanks!
  • Splitting a string