/// <summary>
        
/// 把HTML内容转为UBB代码
        
/// </summary>
        
/// <param name="_Html"></param>
        
/// <returns></returns>
        private string DoHtmlToUBB(string _Html)
        {           
            
            _Html 
= Regex.Replace(_Html, "<br[^>]*>", "\n");
            _Html 
= Regex.Replace(_Html, @"<p[^>\/]*\/>", "\n");
            _Html 
= Regex.Replace(_Html, "\\son[\\w]{3,16}\\s?=\\s*([\'\"]).+?\\1", "");
            _Html = Regex.Replace(_Html, "<hr[^>]*>", "[hr]");

            _Html 
= Regex.Replace(_Html, "<(\\/)?blockquote([^>]*)>", "[$1blockquote]");
            _Html 
= Regex.Replace(_Html, "<img[^>]*smile=\"(\\d+)\"[^>]*>", "'[s:$1]");
            _Html 
= Regex.Replace(_Html, "<img[^>]*src=[\'\"\\s]*([^\\s\'\"]+)[^>]*>", "用C#把HTML内容转为UBB的方法");
            _Html = Regex.Replace(_Html, "<a[^>]*href=[\'\"\\s]*([^\\s\'\"]*)[^>]*>(.+?)<\\/a>", "[url=$1]$2[/url]");

            _Html 
= Regex.Replace(_Html, "<[^>]*?>", "");
            _Html 
= Regex.Replace(_Html, "&amp;", "&");
            _Html 
= Regex.Replace(_Html, "&nbsp;", " ");
            _Html 
= Regex.Replace(_Html, "&lt;", "<");
            _Html 
= Regex.Replace(_Html, "&gt;", ">");

            
return _Html;
        }

相关文章:

  • 2022-01-06
  • 2021-10-22
  • 2021-06-28
  • 2021-06-08
  • 2022-03-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
  • 2021-11-14
相关资源
相似解决方案