tags:

views:

3080

answers:

6

Hi to all.

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

Thanks

+1  A: 

I don't think VB.NET has such a feature.

Mehrdad Afshari
A: 

No, VB.NET does not yet have such a feature. It will be available in the next iteration of VB (visual basic 10) however (link)

Jason Irwin
You sure? I know they're gonna allow multiline statements, but are they gonna allow multiline *strings* too? I mean "hello <newline> world"?
Mehrdad Afshari
Removal of line continuation character and multi-line literal strings are different features.
JaredPar
A: 

if it's like C# (I don't have VB.Net installed) you can prefix a string with @

foo = @"Multiline
String"

this is also useful for things like @"C:\Windows\System32\" - it essentially turns off escaping and turns on multiline.

Andy Hohorst
It's not like C#. That doesn't work.
David
+7  A: 

VB.Net has no such feature and it will not be coming in Visual Studio 2010. The feature that jirwin is refering is called implicit line continuation. It has to do with removing the _ from a multi-line statement or expression. This does remove the need to terminate a multiline string with _ but there is still no mult-line string literal in VB.

Example for multiline string

Visual Studio 2008

Dim x = "line1" & vbCrlf & _
        "line2"

Visual Studio 2010

Dim x = "line1" & vbCrlf & 
        "line2"
JaredPar
+4  A: 

You can use XML Literals to achieve a similar effect:

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 = <a><![CDATA[Hello
World & Space]]></a>.Value
Vincenzo Alcamo
A: 

Well, since you seem to be up on your python, may I suggest that you copy your text into python, like:

 s="""\
  this is gonna 
  last a few lines
  """

then do a:

for i in s.split('\n'):
    print 'mySB.AppendLine("%s")' % i

or

 for i in s.split('\n'):
     print '"%s " & _' % i

then at least you can copy that out and put it in your VB code. Bonus points if you bind a hotkey (fastest to get with:Autohotkey) to do this for for whatever is in your paste buffer. The same idea works good for a SQL formatter.

RichardJohnn