heredoc-like syntax in VB.Net?

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

I would like to send a boatload of pre-formatted text to a string or
stream.

Is there a way to do this in VB.Net similar to the way heredoc works in
other languages?
 
Dennis,

Can you be a little more expressive then a boatload of pre-formatted text

In fact it is then

\\\
dim heremedoc as new stringbuilder
For each thestring as string in my boatload
heremedoc.Add(thestring
Next
dim the boatloadloaded = heremedoc.ToString
///

Cor
 
Hi Dennis,
I would like to do something similar to the way it works in C#. Here is
an example:

http://blog.luckyus.net/2009/02/03/heredoc-in-c-sharp/


Either store the text as a System.String setting, and then use
My.Settings.NameOfsetting as the variable.

Dim boatloadoftext = My.Settings.boatloadoftext

Or,

Dim boatloadoftext As String = "Line 1" & VbControlChars.CRLF_
"Line 2" & VbControlChars.CRLF _
"Line 3" & VbControlChars.CRLF _
"Line 4"

TBH I would go the Settings route, it would mean that you can update the
setting in the .config file, this is the "correct" way to do it. Try to
avoid using String literals as much as possible.

Nick.
 
Either store the text as a System.String setting, and then use
My.Settings.NameOfsetting as the variable.

Dim boatloadoftext = My.Settings.boatloadoftext

This seems to do what I want.
Or,

Dim boatloadoftext As String = "Line 1" & VbControlChars.CRLF_
"Line 2" & VbControlChars.CRLF _
"Line 3" & VbControlChars.CRLF _
"Line 4"

Definitely _not_ what I wanted to end up doing.

Thanks!
 
Hi Dennis,
Definitely _not_ what I wanted to end up doing.

So you want to simply copy and paste a shed load of text into your code?

I'll tell you now, it's bad coding.

Store it in a setting, or if you want to localise the text, store it in
a resource.

Alternatively, don't ask for help if you don't want the correct way of
achieving the results you are after, goto planet-source-code.com.

Nick.
 
Ignore this, I didn't notice your line "This seems to do what I want."...

LOL! I only saw the last line and thought it was in reference to both
solutions, my apologies.
 
Dennis said:
I would like to send a boatload of pre-formatted text to a string or
stream.

Is there a way to do this in VB.Net similar to the way heredoc works in
other languages?

Strings in VB don't accept embedded line breaks. You'll eventually
have to use string concatenation. Or not: what I do is to create a
text file resource.

Go to the project properties, and open the Resources tab. Select "Add
Resource" >> "Add New Text File" and specify a descriptive name for
your string (e.g. SQL_SINCHRONIZE_TABLES, or whatever suits you. Make
it descriptive). The IDE creates a new text file with the name you
provided in the folder Resources. You can edit this file at will.

Now, to use the text, you only need to load it from the My.Resources
namesmace:

Dim Sql As String = My.Resources.SQL_SINCHRONIZE_TABLES

Simple as that.

HTH.

Regards,

Branco.
 
Back
Top