本文介绍了添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在字符串中添加换行符时遇到问题.我尝试使用"\ r \ n",而Environment.NewLine也无法正常工作.
I have a problem with adding line break in a string. I have tried using "\r\n", and Environment.NewLine also does not work.
FirmNames = "";
foreach (var item in FirmNameList)
{
if (FirmNames != "")
{
FirmNames += ", " + LineBreak; -- I want a line break here after the comma ","
}
FirmNames += item;
}
任何人都可以帮忙吗?
推荐答案
正确的答案是使用Environment.NewLine
.它是特定于环境的,并在"\ r \ n"上提供了清晰度(但实际上没有任何区别).
The correct answer is to use Environment.NewLine
, as you've noted. It is environment specific and provides clarity over "\r\n" (but in reality makes no difference).
foreach (var item in FirmNameList)
{
if (FirmNames != "")
{
FirmNames += ", " + Environment.NewLine;
}
FirmNames += item;
}
这篇关于添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!