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.
Use Split () Function This function splits the string into smaller sections. This is the opposite of merging many strings into one. The split () function contains two parameters. In the first parameter, we pass the symbol that is used for the split.
We can use the len() method and get half of the string. We then use the slice notation technique to slice off the first and second of the string value to store the then in separate variables.
Ruby – String split() Method with ExamplesIf pattern is a Regular Expression or a string, str is divided where the pattern matches. Parameters: arr is the list, str is the string, pattern is the either string or regExp, and limit is the maximum entries into the array. Returns: Array of strings based on the parameters.
Use String.Split(Char[], Int32)
overload like this:
string[] array = txtFrom.Text.Split(new char[]{' '},2);
http://msdn.microsoft.com/en-us/library/c1bs0eda.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With