| 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.
Solamain LochPosted Jun 4, 2008, 10:49 PM
DavePosted Jun 4, 2008, 10:44 PM
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);