初写,对c#不熟悉,谢谢

解决方案 »

  1.   

    server.htmlencode()
    server.htmldecode()
      

  2.   

    Public Shared Function change(ByVal str) As String
            Dim result As String
            Dim l As Integer        If str = Nothing Then
                Change = ""
                Exit Function
            End If
            l = Len(str)
            result = ""
            Dim i
            For i = 1 To l
                Select Case Mid(str, i, 1)
                    Case "<"
                        result = result + "&lt;"
                    Case ">"
                        result = result + "&gt;"
                    Case "'"
                        result = result + "''"                Case Chr(13)
                        result = result + "<br>"
                    Case Chr(34)
                        result = result + "&quot;"
                    Case "&"
                        result = result + "&amp;"
                    Case Chr(32)
                        'result=result+"&nbsp;"
                        If i + 1 <= l And i - 1 > 0 Then
                            If Mid(str, i + 1, 1) = Chr(32) Or Mid(str, i + 1, 1) = Chr(9) Or Mid(str, i - 1, 1) = Chr(32) Or Mid(str, i - 1, 1) = Chr(9) Then
                                result = result + "&nbsp;"
                            Else
                                result = result + " "
                            End If
                        Else
                            result = result + "&nbsp;"
                        End If
                    Case Chr(9)
                        result = result + "    "
                    Case Else
                        result = result + Mid(str, i, 1)
                End Select
                'if i>=50 and i Mod lenth=0 and mid(str,i,1)<>"<br>" and mid(str,i,1)<>"<BR>" then result=result+"<BR>"
            Next        Return result
        End Function