换行符未在文本框中正确显示 [英] Newline not showing correctly in textbox

查看:36
本文介绍了换行符未在文本框中正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我的数据库加载一个 string,其中包含换行符 (\r\n).但是,这并没有呈现为新行,而是呈现为 \r\n.

I am loading a string from my database which among other things contains line breaks (\r\n). However, this isn't being rendered as a new line but instead as \r\n.

如果我直接输入而不是从字符串加载它,它工作得很好,但我需要能够从字符串加载它.

If I type it directly in instead of loading it from a string, it works just fine but I need to be able to load it from a string.

有什么想法吗?

仔细检查后,字符串看起来像:

Upon closer inspection, it looks like the string is being returned as:

Changed test7\\r\\nChanged test8\\r\\nChanged test9Changed test7

来自数据库.

我尝试在其上运行 .Replace(@"\\", @"\") 但这根本没有效果.有什么想法吗?

I tried running a .Replace(@"\\", @"\") on it but this had no effect at all. Any ideas?

推荐答案

这将不起作用 .Replace("\\", "\") 因为它将反斜杠视为转义符,但奇怪的是,这在它应该起作用时不起作用: .Replace(@"\\", @"\")

This won't work .Replace("\\", "\") because it sees the backslash as an escape, but strangely, this doesn't work when it should: .Replace(@"\\", @"\")

我开始工作的是:

.Replace("\\r\\n", "\r\n");

这篇关于换行符未在文本框中正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆