Is there a way to have multiline strings in VB.NET like Python
a = """ multi line string """
or PHP?
$a = <<<END multi line string END;
Of course something that is not
"multi" & _ "line
You can specify more than one delimiter. For example, dim result = inputString. Split({vbCrLf, vbLf, vbCr}, StringSplitOptions. RemoveEmptyEntries) will split the input string using \r\n , \n and \r , returning an array of strings.
It is the simplest method to let a long string split into different lines. You will need to enclose it with a pair of Triple quotes, one at the start and second in the end. """Learn Python Programming""" Anything inside the enclosing Triple quotes will become part of one multiline string.
A multiline string in Python begins and ends with either three single quotes or three double quotes. Any quotes, tabs, or newlines in between the “triple quotes” are considered part of the string. Python's indentation rules for blocks do not apply to lines inside a multiline string.
Summary: Python Multiline String gives better readability. Three single quotes, three double quotes, brackets, and backslash can be used to create multiline strings. Whereas the user needs to mention the use of spaces between the strings.
You can use XML Literals to achieve a similar effect:
Imports System.XML Imports System.XML.Linq Imports System.Core Dim s As String = <a>Hello World</a>.Value
Remember that if you have special characters, you should use a CDATA block:
Dim s As String = <![CDATA[Hello World & Space]]>.Value
Multi-line string literals were introduced in Visual Basic 14 (in Visual Studio 2015). The above example can be now written as:
Dim s As String = "Hello World & Space"
MSDN article isn't updated yet (as of 2015-08-01), so check some answers below for details.
Details are added to the Roslyn New-Language-Features-in-VB-14 Github repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With