Thinking in Manito

智慧+汗水=?
posts - 7, comments - 2, trackbacks - 0, articles - 2
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

日历

<2005年11月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

公告

一切于心所想!

文章档案

相册

搜索

  •  

最新评论


public class CodeFilter
{

    public CodeFilter()
    {
    }

    public static String toHtml(String s)
    {
        if(s == null)
        {
            s = "";
            return s;
        } else
        {
            s = Replace(s, "&", "&amp;");
            s = Replace(s, "<", "&lt;");
            s = Replace(s, ">", "&gt;");
            s = Replace(s, "\t", "    ");
            s = Replace(s, "\r\n", "\n");
            s = Replace(s, "\n", "<br>");
            s = Replace(s, " ", "&nbsp;");
            s = Replace(s, "'", "&#39;");
            s = Replace(s, "\\", "&#92;");
            return s;
        }
    }

    public static String unHtml(String s)
    {
        s = Replace(s, "&lt;img&nbsp;src=&#39;", "<img src='");
        s = Replace(s, "&#39;&gt;", "'>");
        s = Replace(s, "&lt;center&gt;", "<center>");
        s = Replace(s, "&lt;/center&gt;", "</center>");
        return s;
    }

    public static String Replace(String s, String s1, String s2)
    {
        StringBuffer stringbuffer = new StringBuffer();
        int i = s.length();
        int j = s1.length();
        int k;
        int l;
        for(k = 0; (l = s.indexOf(s1, k)) >= 0; k = l + j)
        {
            stringbuffer.append(s.substring(k, l));
            stringbuffer.append(s2);
        }

        if(k < i)
            stringbuffer.append(s.substring(k));
        return stringbuffer.toString();
    }
}


只有注册用户登录后才能发表评论。


网站导航: