<分区>
Possible Duplicate:
Multiline strings in VB.NET
在 C# 中,你可以像这样:
string s = @"hello there mister";
VB.NET 是否有类似的不涉及字符串连接的东西?我希望能够在两个双引号之间粘贴多行文本。不知何故,我不相信 VB.NET 支持这一点。
<分区>
Possible Duplicate:
Multiline strings in VB.NET
在 C# 中,你可以像这样:
string s = @"hello there mister";
VB.NET 是否有类似的不涉及字符串连接的东西?我希望能够在两个双引号之间粘贴多行文本。不知何故,我不相信 VB.NET 支持这一点。
最佳答案
编辑:VS2015 ONWARDS
您现在可以像这样在 VS2015 中编写多行字符串:
Dim text as String = "
This
Is
Multiline
Text!"
VB .NET 中没有多行字符串文字 - 您可以获得的最接近的东西(不使用 LINQ)是带连接的多行语句。
VS2010 之前:
Dim x = "some string" & vbCrlf & _
"the rest of the string"
2010 年后:
Dim x = "some string" & vbCrlf &
"the rest of the string"
XML/LINQ 技巧是:
Imports System.Core
Imports System.XML
Imports System.XML.Linq
Dim x As String = <a>Some code
and stuff</a>.Value
但这限制了您可以在 <a></a>
中放置的字符由于 XML 语义而阻塞。如果您需要使用特殊字符,请将文本包装在标准 CDATA
中 block :
Dim x As String = <a><![CDATA[Some code
& stuff]]></a>.Value
关于c# - VB.NET 是否具有等同于 c# 的多行字符串声明语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11954701/