在.NET中我可以同时提供 r
或 ñ
字符串,但有一个办法插入
像新线特殊字符,如 Environment.NewLine
静态属性?
In .NET I can provide both r
or n
string literals, but there is a way to insert
something like "new line" special character like Environment.NewLine
static property?
好了,简单的选项有:
的String.Format
:
string x = string.Format("first line{0}second line", Environment.NewLine);
字符串连接:
String concatenation:
string x = "first line" + Environment.NewLine + "second line";
路线插值(在C#6及以上):
String interpolation (in C#6 and above):
string x = $"first line{Environment.NewLine}second line";
您也可使用 n随处可见,并替换:
You could also use n everywhere, and replace:
string x = "first linensecond linenthird line".Replace("n",
Environment.NewLine);
请注意,你不能让这个字符串的恒的,因为 Environment.NewLine
的价值将只提供在执行时。
Note that you can't make this a string constant, because the value of Environment.NewLine
will only be available at execution time.
上一篇:登录网站,并使用cookie来获取源另一页网站、cookie
下一篇:我能做些什么来解决"未找到行或更改"例外的LINQ to SQL在SQL Server Compact Edition数据库?我能、做些什么、未找到、数据库