Windows Phone Developers

Thursday, September 15, 2011

How to Remove Alternate/Extra Text (Text within Parenthesis) using VB.NET/C#

How to Remove Text within Brackets/ Braces using VB.NET/C#

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, "");
        }

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005