public string HtmlDecode(string str)
{
if ((str.Trim()!="") || (str.Trim()!=null))
{
str.Replace(">",">");  
str.Replace("&lt;","<");
str.Replace("&nbsp;",Chr(32));
str.Replace("&nbsp;",Chr(9));   
str.Replace("&quot;",Chr(34));  
str=Replace("&#39;",Chr(39));  
   
str.Replace("",Chr(13));
str.Replace("</p><p>",Chr(10)+ Chr(10));
str.Replace("<br> ",Chr(10));
return str;
}
}编译不能通过,chr在名称空间中不存在,怎么办呀?

解决方案 »

  1.   

    Public Function Encode(ByVal strParamer As String) As String
            strParamer = Replace(strParamer, "&", "&amp;")
            strParamer = Replace(strParamer, "'", "''")
            strParamer = Replace(strParamer, " ", "&nbsp;")
            strParamer = Replace(strParamer, "<", "&lt;")
            strParamer = Replace(strParamer, ">", "&gt;")
            strParamer = Replace(strParamer, "\n", "<br>")
            Return strParamer
        End Function
        Public Function Decode(ByVal strParamer As String) As String
            strParamer = Replace(strParamer, "<br>", "\n")
            strParamer = Replace(strParamer, "&gt;", ">")
            strParamer = Replace(strParamer, "&lt;", "<")
            strParamer = Replace(strParamer, "&nbsp;", " ")
            strParamer = Replace(strParamer, "''", "'")
            strParamer = Replace(strParamer, "&amp;", "&")
            Return strParamer
        End Function
      

  2.   

    Server.HtmlEncode();
    Server.HtmlDecode();.Net自带的。
      

  3.   

    建议楼主用楼上的.
    CHR是VB(VB.net里有没有不知道)的函数.其实楼主不用弄这么多,我就只换四个:<   >   '   \r\n
    不知道各位有什么意见.转换了这四个,目前来说,我认为SQL和JS都攻不进来了.
      

  4.   

    我也觉得四楼的方法就行.
    学习ING~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      

  5.   

    To:jerrycool(子风)
    主要还有一个在发新闻的时候保持排版的问题!谢谢楼上的各位师兄!
      

  6.   

    我是这样做的.用一个HTMLEDIT(自己全改了FTB的),再在服务器端首页换<为&gt;,再找到我允许的标签,如<b>,就把&gt;换成<.还有结束标签.
    这样又安全(目前我还看不出来有什么不妥),又能保持排版,还是很的直观