Alex Rivera | Logout

Splitting a String into only 2 parts

Asked 2011-05-06T03:50:16.163
19

I want to take a string from a textbox (txtFrom) and save the first word and save whatever is left in another part. (the whatever is left is everything past the first space)

Example string = "Bob jones went to the store"

array[0] would give "Bob"
array[1] would give "jones went to the store"

I know there is string[] array = txtFrom.Split(' '); , but that gives me an array of 6 with individual words.

Edit
Report

1 Answer

3

There is an overload of the String.Split() method which takes an integer representing the number of substrings to return.

So your method call would become: string[] array = txtFrom.Text.Split(' ', 2);

answered 2011-05-06T03:54:16.573

Your Answer