Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline strings in VB.NET

Tags:

string

vb.net

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 
like image 995
pistacchio Avatar asked Apr 01 '09 16:04

pistacchio


People also ask

How do I split a string into multiple lines in VB net?

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.

What is multiline string example?

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.

What is a 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.

What is the use of 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.


1 Answers

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 

2015 UPDATE:

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.

like image 112
Vincenzo Alcamo Avatar answered Oct 19 '22 19:10

Vincenzo Alcamo