且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Pre在网页中显示文字

更新时间:2023-12-06 15:40:16

您必须在样式表中定义不同标记类型的样式以自定义格式,然后将其包含在Web控件/表单中. blockquote>
 <   textarea    名称  ="   width   38  高度  =   10  > 
<% = Server.HTMLEncode(sValue)%> 
<  /textarea  >  



 功能 HTMLDecode(sText)
    昏暗我
    sText = Replace(sText," ,Chr(" ,Chr(" ,Chr(" ,Chr(" ,Chr(对于 I =  1    255 
        sText = Replace(sText," & I&  ;",Chr(I))
    下一步
    HTMLDecode = sText
结束 功能 



您可以使用javascript函数在客户端进行操作


Hi,

I try to show the program text in a web page just like CodeProject; however, somehow I just can not get the right combination! I tried all 4 combinations with no result. What is the secret?


<%
CR = chr(10)

Text = "<table border=""1"" bordercolor=""#660066"">" & CR
Text = Text & "<tr><td>test line 1</td></tr>" & CR
Text = Text & "<tr><td>test line 2</td></tr>" & CR


        NText = replace(text, "<", "&lt;")
        Ntext = replace(Ntext, ">", "&gt;" )
        Ntext = replace(Ntext, "&", "&amp;")
        Ntext = replace(Ntext, """", "&quot;")
        Ntext = replace(Ntext, Chr(10), "<br>")


%>
<table border="1" bordercolor="#FF0000">
<tr><td>
<b>Original No Pre</b><br><%=text%>
</td></tr>
<tr><td>
<b>Original wz Pre</b><br><pre><%=text%></pre>
</td></tr>
<tr><td>
<b>Converted No Pre</b><br><%=ntext%>
</td></tr>
<tr><td>
<b>Converted wz Pre</b><br><pre><%=ntext%></pre>
</td></tr>
</table>



rgds,
kfl.

You have to define the styles for the different tag types in a Stylesheet to customize the formatting and then include that in your web control/form.


<textarea name="sample" width=38 height=10>
<%= Server.HTMLEncode(sValue) %>
</textarea>



Function HTMLDecode(sText)
    Dim I
    sText = Replace(sText, "&quot;", Chr(34))
    sText = Replace(sText, "&lt;"  , Chr(60))
    sText = Replace(sText, "&gt;"  , Chr(62))
    sText = Replace(sText, "&amp;" , Chr(38))
    sText = Replace(sText, "&nbsp;", Chr(32))
    For I = 1 to 255
        sText = Replace(sText, "&#" & I & ";", Chr(I))
    Next
    HTMLDecode = sText
End Function



You can do it on client-side with javascript functions