Possible Duplicate:
Multiline strings in VB.NET
In c#, you can be all like:
string s = @"hello there mister";
Does VB.NET have something similar that doesn't involve string concatenation? I'd like to be able to paste multi-line text in between two double quotes. Somehow, I don't believe VB.NET supports this.
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.
You can have a string split across multiple lines by enclosing it in triple quotes. Alternatively, brackets can also be used to spread a string into different lines. Moreover, backslash works as a line continuation character in Python. You can use it to join text on separate lines and create a multiline string.
EDIT: VS2015 ONWARDS
YOU CAN NOW HAVE MULTILINE STRINGS IN VS2015 BY WRITING THEM LIKE SO:
Dim text as String = "
This
Is
Multiline
Text!"
There is no multi-line string literal in VB .NET - the closest thing you can get (without using LINQ) is a multi-line statement with concatenation.
Prior to VS2010:
Dim x = "some string" & vbCrlf & _
"the rest of the string"
Post 2010:
Dim x = "some string" & vbCrlf &
"the rest of the string"
The XML/LINQ trick is:
Imports System.Core
Imports System.XML
Imports System.XML.Linq
Dim x As String = <a>Some code
and stuff</a>.Value
But this limits what characters you can place inside the <a></a>
block because of XML semantics. If you need to use special characters wrap the text in a standard CDATA
block:
Dim x As String = <a><![CDATA[Some code
& stuff]]></a>.Value
No, but you can use a xml trick like this:
Dim s As String = <a>hello
there
mister</a>.Value
or put your string in a project resource.
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