简体   繁体   English

回车

[英]carriage return

Using C# I have a WPF text box which accepts carriage returns. 使用C#,我有一个WPF文本框,它接受回车。 It saves into the SQL database as a carriage return (I have checked the ASCII on this) but when the application pulls it from the database and into a string and then prints it using HTML with no carriage return. 它作为回车符保存到SQL数据库中(我已经检查了ASCII),但是当应用程序将其从数据库中提取到字符串中,然后使用不带回车符的HTML打印时。 How can I get the string to recognize the carriage return? 如何获得识别回车符的字符串?

HTML doesn't display new lines based on carriage return, it uses specific markup: <br/> HTML不会根据回车符显示新行,而是使用特定的标记: <br/>

Quick fix would be to convert all your new lines before rendering it as html... 快速解决方法是在将所有新行呈现为html之前进行转换。

string html = text.Replace(Environment.NewLine, "<br/>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM