在 VB.NET 中是否有像 Python 一样的多行字符串的方法?
a = """
multi
line
string
"""
选择什么,PHP还是Python?
$a = <<<END
multi
line
string
END;
当然,如果一个东西不是
"multi" & _
"line
在 VB.NET 中是否有像 Python 一样的多行字符串的方法?
a = """
multi
line
string
"""
选择什么,PHP还是Python?
$a = <<<END
multi
line
string
END;
当然,如果一个东西不是
"multi" & _
"line
Dim a = My.Resources.Whatever_you_chose
声明:我喜欢Python。它的多行字符串只是其中一个原因。
但我也会VB.Net,所以这里是我用于更易读的长字符串的快捷方式。
Dim lines As String() = {
"Line 1",
"Line 2",
"Line 3"
}
Dim s As String = Join(lines, vbCrLf)
dim vrstr as string = <s>
some words
some words
some
words
</s>
Dim HtmlSample As String = <anything>what ever you want to type here with multiline strings</anything>
dim Test1 as string =<a>onother multiline example</a>
作为 Visual Studio 2015 的一部分,Visual Basic 14 可用。https://msdn.microsoft.com/en-us/magazine/dn890368.aspx
但是 R# 尚不支持。好消息是它们将很快得到支持!请在 Youtrack 上投票,通知 JetBrains 您也需要它们。
<Tag><%= New XCData(T.Property) %></Tag>
System.Text.StringBuilder
类:Dim sValue As New System.Text.StringBuilder
sValue.AppendLine("1st Line")
sValue.AppendLine("2nd Line")
sValue.AppendLine("3rd Line")
然后你可以使用以下代码获取多行字符串:
sValue.ToString()
由于这是一个可读性问题,我使用了以下代码:
MySql = ""
MySql = MySql & "SELECT myTable.id"
MySql = MySql & " FROM myTable"
MySql = MySql & " WHERE myTable.id_equipment = " & lblId.Text
使用 vbCrLf
或 vbNewLine
。我已经测试过它可以在消息框和许多其他控件中正常工作。
Dim str As String
str = "First line" & vbCrLf & "Second line"
MsgBox(str)
str = "First line" & vbNewLine & "Second line"
MsgBox(str)
它将显示两个带有2行的相同MessageBox。
不,VB.NET目前还没有这样的功能。 但是在下一版VB(Visual Basic 10)中将可用(link)。