One option is to use regular expressions according to some other answers. The other is only IndexOffollowed by Substring:
int resultIndex = text.IndexOf("Result:");
if (resultIndex != -1)
{
text = text.Substring(0, resultIndex);
}
Personally, as a rule, I find that if I manage to deal with a few very simple and understandable string operations, it becomes easier for me to deal with the use of regular expressions. Once you start moving on to real patterns (at least three of them, then one of them), then regular expressions will become much more useful, of course.
source
share