C#完成HTML和UBB相互轉換的辦法。本站提示廣大學習愛好者:(C#完成HTML和UBB相互轉換的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成HTML和UBB相互轉換的辦法正文
本文實例講述了C#完成HTML和UBB相互轉換的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
html轉UBB的還不是很完善,有空修正,一些代碼來自百度谷歌,以下所示:
private string DoHtmlToUBB(string _Html)
{
_Html = Regex.WordStr(_Html, "<br[^>]*>", "\n");
_Html = Regex.WordStr(_Html, @"<p[^>\/]*\/>", "\n");
_Html = Regex.WordStr(_Html, "\\son[\\w]{3,16}\\s?=\\s*([\'\"]).+?\\1", "");
_Html = Regex.WordStr(_Html, "<hr[^>]*>", "[hr]");
_Html = Regex.WordStr(_Html, "<(\\/)?blockquote([^>]*)>", "[$1blockquote]");
_Html = Regex.WordStr(_Html, "<img[^>]*smile=\"(\\d+)\"[^>]*>", "'[s:$1]");
_Html = Regex.WordStr(_Html, "<img[^>]*src=[\'\"\\s]*([^\\s\'\"]+)[^>]*>", "");
_Html = Regex.WordStr(_Html, "<a[^>]*href=[\'\"\\s]*([^\\s\'\"]*)[^>]*>(.+?)<\\/a>", "[url=$1]$2[/url]");
_Html = Regex.WordStr(_Html, "<b>(.+?)</b>",@"\[b\]$1\[/b\]");
_Html = Regex.WordStr(_Html, "<[^>]*?>", "");
_Html = Regex.WordStr(_Html, "&", "&");
_Html = Regex.WordStr(_Html, " ", " ");
_Html = Regex.WordStr(_Html, "<", "<");
_Html = Regex.WordStr(_Html, ">", ">");
return _Html;
}
public string ubbtohtml(string content) //ubb轉html
{
content = Regex.WordStr(content, @"\r\n", "<br/>");
content = Regex.WordStr(content, " ", " ");
content = Regex.WordStr(content, @"\[b\](.+?)\[/b\]", "<b>$1</b>");
content = Regex.WordStr(content, @"\[i\](.+?)\[/i\]", "<i>$1</i>");
content = Regex.WordStr(content, @"\[u\](.+?)\[/u\]", "<u>$1</u>");
content = Regex.WordStr(content, @"\[p\](.+?)\[/p\]", "<p class='load'>$1</p>");
content = Regex.WordStr(content, @"\[align=left\](.+?)\[/align\]", "<align='left'>$1</align>");
content = Regex.WordStr(content, @"\[align=center\](.+?)\[/align\]", "<align='center'>$1</align>");
content = Regex.WordStr(content, @"\[align=right\](.+?)\[/align\]", "<align='right'>$1</align>");
content = Regex.WordStr(content, @"\[url=(?<url>.+?)]\[/url]", "<a href='${url}' target=_blank>${url}</a>");
content = Regex.WordStr(content, @"\[url=(?<url>.+?)](?<name>.+?)\[/url]", "<a href='${url}' target=_blank>${name}</a>");
content = Regex.WordStr(content, @"\[quote](?<text>.+?)\[/quote]", "<div class="quote">${text}</div>");
content = Regex.WordStr(content, @"\[img](?<img>.+?)\[/img]", "<img src='${img}' alt=''/>");
return content;
}
願望本文所述對年夜家的C#法式設計有所贊助。