可能重复:
VB.NET中的多行字符串
在c#中,你可以像:
string s = @"hello there mister";
VB.NET是否有类似的东西不涉及字符串连接?我希望能够在两个双引号之间粘贴多行文本.不知何故,我不相信VB.NET支持这一点.
Mat*_*zza 15
编辑:VS2015 ONWARDS
你现在可以通过写它来制作VS2015中的多条线:
Dim text as String = "
This
Is
Multiline
Text!"
Run Code Online (Sandbox Code Playgroud)
VB .NET中没有多行字符串文字 - 你可以得到的最接近的东西(不使用LINQ)是带有连接的多行语句.
在VS2010之前:
Dim x = "some string" & vbCrlf & _
"the rest of the string"
Run Code Online (Sandbox Code Playgroud)
2010年后:
Dim x = "some string" & vbCrlf &
"the rest of the string"
Run Code Online (Sandbox Code Playgroud)
XML/LINQ技巧是:
Imports System.Core
Imports System.XML
Imports System.XML.Linq
Dim x As String = <a>Some code
and stuff</a>.Value
Run Code Online (Sandbox Code Playgroud)
但这限制了<a></a>由于XML语义而可以在块内放置的字符.如果需要使用特殊字符将文本包装在标准CDATA块中:
Dim x As String = <a><![CDATA[Some code
& stuff]]></a>.Value
Run Code Online (Sandbox Code Playgroud)
不,但你可以使用像这样的xml技巧:
Dim s As String = <a>hello
there
mister</a>.Value
Run Code Online (Sandbox Code Playgroud)
或者将您的字符串放在项目资源中.