且构网

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

保持在 asp.net 文本框中输入的格式(回车、换行等)

更新时间:2023-01-25 08:24:59

假设您使用的是 C#,您可以在页面上显示字符串时执行以下操作

Assuming you're using C# you can do the following when you display the string on the page

theStringYouWantToFormat.Replace(char.ConvertFromUtf32(13),"<br/>")

当您对从文本框中获取的值调用 Server.HtmlEncode 时,它会查看文本并对包含在该文本框中的任何 HTML 标记进行编码,例如 <script></script> 将被编码为 &lt;script&gt;&lt;/script>.

When you call Server.HtmlEncode on the value you grab from a text box it'll look at the text and encode any HTML tags contained in that text box so for example <script></script> would be encoded to &lt;script&gt;&lt;/script&gt;.