我有一些文本(例如“o\nour first place, and this\n\n13”)我希望文本中的每个“\n”字符串都必须用换行符替换...
该示例的输出将是:
哦 我们的第一名,还有这个
13 我该如何制作?文本框是多行的
代码是
string text_str = txtbox.Text;
text_str .Replace("(?<!\r)\n", "\r\n");
txtbox.Clear();
txtbox.Text = text_str;
最佳答案
我认为您正在寻找这样的东西:
string text_str = txtbox.Text;
text_str = text_str.Replace("\\n", "\r\n");
txtbox.Clear();
txtbox.Text = text_str;
虽然这是一种非常迂回的做事方式。这将完成同样的事情:
txtbox.Text = txtbox.Text.Replace("\\n", "\r\n");
关于c# 在文本框中用换行符替换 "\n"文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31223330/