I need help using the Split function in C#. The user needs to enter a 3 word phrase or more. I already know what the users first word will be. For example if the user enters 'Microsoft Visual Studio 2015', I already know the user will enter 'Microsoft'. How can I get Split to cut off the first word and give only the following phrase as a string?
char[] separators = { ' ' };
string secondword = myString.Split(separators, 2)[1];
Will give you the right output. The split statement with an int argument specifies that you want to return at most 2 substrings, and the array index [1] directs the second of those (whatever is after the first space) to be your output.
If you need the first word you can do similar:
char[] separators = { ' ' };
string firstword= myString.Split(separators, 2)[0];
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