zoukankan      html  css  js  c++  java
  • 将UBB编码转成标准的HTML代码

    /// <summary>
    /// 将UBB编码转成标准的HTML代码
    /// </summary>
    /// <param name="argString"></param>
    /// <returns></returns>
    public static string HtmlDecode(string argString)
    {
    string tString = argString;
    if (tString != "")
    {
    Regex tRegex;
    bool tState = true;
    tString = tString.Replace("&", "&amp;");
    tString = tString.Replace(">", "&gt;");
    tString = tString.Replace("<", "&lt;");
    tString = tString.Replace(""", "&quot;");
    tString = Regex.Replace(tString, @"[br]", "<br />", RegexOptions.IgnoreCase);
    string[,] tRegexAry = {
    {@"[p]([^[]*?)[/p]", "$1<br />"},
    {@"[b]([^[]*?)[/b]", "<b>$1</b>"},
    {@"[i]([^[]*?)[/i]", "<i>$1</i>"},
    {@"[u]([^[]*?)[/u]", "<u>$1</u>"},
    {@"[ol]([^[]*?)[/ol]", "<ol>$1</ol>"},
    {@"[ul]([^[]*?)[/ul]", "<ul>$1</ul>"},
    {@"[li]([^[]*?)[/li]", "<li>$1</li>"},
    {@"[code]([^[]*?)[/code]", "<div class="ubb_code">$1</div>"},
    {@"[quote]([^[]*?)[/quote]", "<div class="ubb_quote">$1</div>"},
    {@"[color=([^]]*)]([^[]*?)[/color]", "<font style="color: $1">$2</font>"},
    {@"[hilitecolor=([^]]*)]([^[]*?)[/hilitecolor]", "<font style="background-color: $1">$2</font>"},
    {@"[align=([^]]*)]([^[]*?)[/align]", "<div style="text-align: $1">$2</div>"},
    {@"[url=([^]]*)]([^[]*?)[/url]", "<a href="$1">$2</a>"},
    {@"[img]([^[]*?)[/img]", "<img src="$1" />"}
    };
    while (tState)
    {
    tState = false;
    for (int ti = 0; ti < tRegexAry.GetLength(0); ti++)
    {
    tRegex = new Regex(tRegexAry[ti, 0], RegexOptions.IgnoreCase);
    if (tRegex.Match(tString).Success)
    {
    tState = true;
    tString = Regex.Replace(tString, tRegexAry[ti, 0], tRegexAry[ti, 1], RegexOptions.IgnoreCase);
    }
    }
    }
    }
    return tString;
    }

  • 相关阅读:
    【足迹C++primer】32、定制操作_2
    pom文件miss artifact com.sun:tools:jar:1.5.0:system问题
    cents上运行wget报错:unable to resolve host address
    怎样定义函数模板
    06006_redis数据存储类型——String
    雷林鹏分享:C# 类型转换
    雷林鹏分享:C# 运算符
    雷林鹏分享:C# 循环
    雷林鹏分享:C# 判断
    雷林鹏分享:C# 方法
  • 原文地址:https://www.cnblogs.com/jiangyunfeng/p/10905803.html
Copyright © 2011-2022 走看看