| Ok,
put really simply I need to know the quickest/best way to separate the
first word in a sentence from the rest of the sentence, and have each
stored in a different string.
For example, Start with: Sentence = "This is the sentence I want to split up." and end up with String1 = "This" String2 = "is the sentence I want split up" The reason I am looking for the quickest way to do this is that it is something the program I am working on will have to do constantly, so any little bit of time saved will add up quickly. |
|
Breaking up a string
First, I would like to apologize if the answer to my question is common knoledge, but as I am new to C# it seems that I no longer have any common sence let allone common knoledge.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Dave131 reputationPosted Jun 4, 2008, 6:44 PM EDT
int firstSpace, len;
String sentence = "This is the sentence I want to split up.";
firstSpace = sentence.IndexOf(' ');
String firstWord = sentence.Substring(0, firstSpace);
sentence = sentence.Substring(firstSpace + 1);
Console.WriteLine(firstWord);
Console.WriteLine(sentence);
Solamain Loch3 reputationPosted Jun 4, 2008, 6:49 PM EDT