×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

try this, I used C#2.0, but easy to switch

string html = @"<ll>abcdefg</ll> <pp>1234567</pp>";
bool isValid = true;
List<byte> buffer = new List<byte>();
foreach (byte x in html.ToCharArray())
{
if (x == '<')
{
isValid = false;
}
if (isValid == true)
{
buffer.Add(x);
}
if (x == '>')
{
isValid = true;
}
}

string cleanString = Encoding.ASCII.GetString(buffer.ToArray());
MessageBox.Show(cleanString);
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / 有一些HTML Code,想去掉里面的HTML tag,只要留文本, 用c#+.net 1.1怎么写。谢谢。
    • try this in c#:
      string strHtmlCode = "<html><body width=123>test</body></html>";
      Regex r = new Regex("<[^<>]+>");
      foreach(Match m in r.Matches(strHtmlCode))
      strHtmlCode = strHtmlCode.Replace(m.ToString(),"");
      Response.Write(strHtmlCode);


      A good site about regex:
      http://www.regular-expressions.info/quickstart.html
      • not only about regex, how about this one "<body>Professor wrote, <b>0<1, 2>1</b></body>"
        • 这个能正确显示吗?要是&lt;&gt;才行吧?
        • Good point. So the user need define a better regular expression.
    • try this, I used C#2.0, but easy to switch
      string html = @"<ll>abcdefg</ll> <pp>1234567</pp>";
      bool isValid = true;
      List<byte> buffer = new List<byte>();
      foreach (byte x in html.ToCharArray())
      {
      if (x == '<')
      {
      isValid = false;
      }
      if (isValid == true)
      {
      buffer.Add(x);
      }
      if (x == '>')
      {
      isValid = true;
      }
      }

      string cleanString = Encoding.ASCII.GetString(buffer.ToArray());
      MessageBox.Show(cleanString);