如何在字符串的两行之间添加空格?
例如:
string words = "Twelve Million Three Hundred and Forty-Five\n Thousand Six Hundred Seventy-Eight Only"
显示为:
期望的结果:
感谢。
重新编辑:对不起Theres已经反斜杠了N,我不想换新线,我已经有了一条新线,只是我需要两条线之间的空间,我认为它被称为领先空间。
答案 0 :(得分:1)
像这样使用Environment.NewLine:
string words = "Twelve Million Three Hundred and Forty-Five" + Environment.NewLine + "Thousand Six Hundred Seventy-Eight Only";
如果要在两行之间添加空行,请像这样使用Environment.NewLine两次:
string words = "Twelve Million Three Hundred and Forty-Five" + Environment.NewLine + Environment.NewLine + "Thousand Six Hundred Seventy-Eight Only";
答案 1 :(得分:1)
使用字符串格式代替' +'防止重新分配内存。
TODO:
string words = string.format("{0}{1}{2}","Twelve Million Three Hundred and Forty-Five",Environment.NewLine,"Thousand Six Hundred Seventy-Eight Only");
不是Todo:
string words = "Twelve Million Three Hundred and Forty-Five" + Environment.NewLine + "Thousand Six Hundred Seventy-Eight Only";