C# - 多行逐字字符串不包含Visual Studion中新线条2022中的新线的托架返回(\ r)
在 Visual Studio 2022 中定义逐字多行字符串 (@"some string"
) 时,我们遇到问题。尽管我们在 Windows 计算机上编译代码,并且变量 Environment.NewLine
定义 < code>\r\n 作为新行,逐字多行字符串仅包含 \n
。见下文。
有人知道为什么字符串中缺少回车符吗?
We are facing issue when defining verbatim multiline strings (@"some string"
) in Visual Studio 2022. Although we are compling code on Windows machine and variable Environment.NewLine
defines \r\n
as new line, verbatim multiline string contains just \n
. See below.
Does anybody have idea why carriage return is missing in string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于找到答案了,感谢 John Skeet 给了我提示。
行为是由代码编辑器引起的 - 在我们的例子中是 Visual Studio 2022。基本上每个代码编辑器都允许您定义换行行为,并且您可以通过
.editorconfig
中的设置覆盖它 - 属性end_of_line< /code> - 请参阅文档
这是
.editorConfig
的示例文件:您还可以使用
.gitattributes
定义 Git 存储库中文件的行为 文件:Visual Studio 还允许您使用选项
Edit->Advanced->Set End of Line 重新格式化当前文件序列
但这仅适用于当前打开的文件。Finally found answer, thanks to John Skeet who gave me a hint.
Behaviour was caused by the code editor - in our case Visual Studio 2022. Basically each code editor allows you to define line breaks behaviour and you can override it by settings in
.editorconfig
- propertyend_of_line
- see documentationHere is an example of the
.editorConfig
file:You can also define behaviour for files in Git repository using
.gitattributes
file:Visual Studio also allows you to reformat current file using option
Edit->Advanced->Set End of Line Sequence
but this is just applied to currently opened file.