换行符未在文本框中正确显示 [英] Newline not showing correctly in textbox
问题描述
我正在从我的数据库加载一个 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屋!