Regular expressions come handy when we have this kind of requirement. Regex.Replace method can be used remove the unwanted text
private static void RemoveTextWithinParens()
{
string pattern = @"\([^\(\)]+\)";
string interesting_string = "SOMETHING (#2) and some more rhing (#3 inside braces)";
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(interesting_string);
string removed_String = rgx.Replace(interesting_string, "");
}
No comments:
Post a Comment