有这样字符串:<li><a href="/q?ct=24&cm=16&tn=ucframework#ask" id="status-my-ask" target="_blank">我的提问</a></li><li><a href="/q?ct=24&cm=16&tn=ucframework#answer" id="status-my-answer" target="_blank">我的回答</a></li><li><a href="http://zhidao.baidu.com/q?ct=24&;cm=16&tn=ucframework#push" target="_blank">为我推荐的提问</a></li>从这些html源码中我只要抽取文本部分,就是说把所有的<>括号去掉,而且括号里面的连接也去掉...只要标签部分
结果: 我的提问 ,  我的回答, 为我推荐的提问. 
就这样..谢谢

解决方案 »

  1.   

    如果是在网页上用JS就能实现
    var txt1 = GetElementById('status-my-ask').InnerText;
    var txt2 = GetElementById('status-my-answer').InnerText;
    txt1,txt2的值就是我的提问,我的回答。
    第三个没有Id取的时候比较麻烦,可以用GetElementByTagName取到所有的a标签再遍历。最好还是设置一个id。。
      

  2.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.IO;
    namespace sxLdfang
    {
        class Program
        {
            static void Main(string[] args)
            {
                string html = @"<li><a href=""/q?ct=24&cm=16&tn=ucframework#ask"" id=""status-my-ask"" target=""_blank"">我的提问</a></li><li><a href=""/q?ct=24&cm=16&tn=ucframework#answer"" id=""status-my-answer"" target=""_blank"">我的回答</a></li><li><a href=""http://zhidao.baidu.com/q?ct=24&;cm=16&tn=ucframework#push"" target=""_blank"">为我推荐的提问</a></li>";
                string pattern = @"(?<=<li><a[^>]+>)[^<>]+(?=</a></li>)";
                MatchCollection mc = Regex.Matches(html, pattern);
                foreach (Match m in mc)
                {
                    Console.WriteLine(m.Value);
                }
                Console.ReadKey();
            }
        }
    }
    运行结果:
    我的提问
    我的回答
    为我推荐的提问
      

  3.   

    我的意思不是针对这个字符串...而是html源码中的全部由括号包含的内容要去掉
      

  4.   

    用WebBrowser控件,打开网页后,获取InnerText属性即可。
    正则的话
    string dest = Regex.Replace(yourHtml,@"<\w+\s[^>]*>",string.Empty);
      

  5.   

    正则表达式:>([^<>]+)<
    http://hi.csdn.net/attachment/201202/13/309620_1329100367nxxg.jpg
      

  6.   

    Regex.Replace(yourHtml,@"(?is)<(?:!|/)?[a-z][a-z0-9]*[^<>]*>",string.Empty);