Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all the word in a string except for the first one

Tags:

string

c#

.net

I am trying to split the string in a word array, and get all the word except for the first word. Like something like this:

string s = "Hello World I am on stack overflow";

string result would give me: "World I am on stack overflow" This is what I've tried:

 string First = "Hello World, This is First Sentence";
 string words = First.Split(' ');
 string AfterWord = words[First.Length-1];`
like image 657
HelloWorld1337 Avatar asked Dec 13 '25 08:12

HelloWorld1337


1 Answers

There's an overload of String.Split() that does this for you:

string sentence = "Hello World, This is First Sentence";
string words = sentence.Split(' ', 2);
string afterWord = words[1];

[and it's a lot more efficient that joining them back up again afterwards]

like image 194
Ian Mercer Avatar answered Dec 15 '25 20:12

Ian Mercer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!