C#如何才能过滤特定的字符?例如在TextBox1里有一篇文章:           1,511 Votes Taxes are the pits, but at least they don't discriminate — everybody has to pay 'em. And that includes the leader of the free world and his right-hand man.The tax returns for President Obama and Vice President Biden were recently released to the public. Quicker than you can say "spread the wealth," searches on both documents skyrocketed. Now, normally tax returns don't inspire a lot of buzz. But when it's the Obamas' and the Bidens', the 1040s are actually pretty interesting. According to an article from Reuters, President Obama (who filed jointly with his wife, Michelle), reported an adjusted gross income of $2,656,902. They paid roughly $855,000 in federal income taxes and almost $78,000 in state income taxes.Now hold up—since when do (honest) politicians make millions of dollars? Well, normally they don't. But Mr. Obama is also a best-selling author. The majority of his 2008 income came from sales of his two memoirs, "Dreams of My Father" and "The Audacity of Hope." Interestingly, the Obamas' income took a substantial drop in 2008. According to Fox News, the couple actually pulled in $4.2 million in 2007.In comparison to his boss's return, Vice President Biden's 1040 looked downright modest. The VP and his wife reported an income of $269,256 for 2008. That's roughly a tenth of what the Obamas declared. Still, a good portion of that came from sales of Mr. Biden's memoir, "Promises to Keep." UPI reports that the Bidens reported donations of $1,885 to charity in 2008, but the White House notes that the Bidens made additional donations to their church that weren't included (lest you think they're stingy). If you'd like to take a gander at the actual tax returns, you can click here for the Obamas', and here for the Bidens'. 
用户点击Button1按钮后,把括号里的注释,连同括号本身都过滤掉。
就是要一次性替换,不能像Windows的记事本里的查找功能一个个地查找,然后用空格替换。这样肯定不行,效率也非常低。而且,不同的括号里的内容也不是相同的。
我估计要用正则表达式实现这个功能。这个用C#如何实现?

解决方案 »

  1.   

    通过正则替换相关字符public static string NoHTML(string Htmlstring)
            {
               Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                //删除HTML
                Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);            Htmlstring.Replace("<", "");
                Htmlstring.Replace(">", "");
                Htmlstring.Replace("\r\n", "");
                Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();            return Htmlstring;
            }
      

  2.   

    TextBox1.Text = Regex.Replace(TextBox1.Text, @"\([^()]*\)", "");
      

  3.   

    这一句应该就行了
    Regex.Replace(输入, @"\([^\)]\)", "", RegexOptions.IgnoreCase); 
      

  4.   

    try...string result = Regex.Replace(yourStr, @"\([^()]*\)", "");
      

  5.   

    ...
    打开帖子才出去一下而已,结果回帖比wuyi8808慢了7分钟
    看来是太久不抢分了,速度明显比不上当年了
      

  6.   

    用正则表达式简单点
    Regex.Replace(输入, @"\([^()]*\)", "", RegexOptions.IgnoreCase);