Home All Groups Group Topic Archive Search About

heredoc-like syntax in VB.Net?

Author
4 Jun 2009 5:18 PM
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

Author
4 Jun 2009 6:15 PM
Cor Ligthert[MVP]
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

Show quoteHide quote
"Dennis" <nobody@nowhere.invalid> wrote in message
news:a50g25d0vpd4edep52onnf9rbposofa0jn@4ax.com...
>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
Author
4 Jun 2009 6:29 PM
Dennis
On Thu, 4 Jun 2009 20:15:22 +0200, "Cor Ligthert[MVP]"
<Notmyfirstn***@planet.nl> wrote:

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

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/

--

Dennis
Author
4 Jun 2009 7:48 PM
nak
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.
Author
4 Jun 2009 8:04 PM
Dennis
On Thu, 4 Jun 2009 20:48:43 +0100, "nak" <a@a.com> wrote:

>> 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

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!

--

Dennis
Author
4 Jun 2009 8:21 PM
nak
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.
Author
4 Jun 2009 8:25 PM
nak
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.

Show quoteHide quote
"nak" <a@a.com> wrote in message
news:4BDD110A-2E73-481F-BBE4-B6A7F1EACF9D@microsoft.com...
> 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.
>
Author
4 Jun 2009 9:45 PM
Family Tree Mike
Show quote Hide quote
"Dennis" <nobody@nowhere.invalid> wrote in message
news:be4g2557sbnlfh1d57v4klmsjffkjebb68@4ax.com...
> On Thu, 4 Jun 2009 20:15:22 +0200, "Cor Ligthert[MVP]"
> <Notmyfirstn***@planet.nl> wrote:
>
>>Can you be a little more expressive then a boatload of pre-formatted text
>
> 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/
>
> --
>
> Dennis


That's not advisable even if you were using C#...

--
Mike
Author
4 Jun 2009 6:43 PM
Peter Macej
Maybe my macro at http://www.helixoft.com/blog/archives/12 can help you.

--
Peter Macej
Helixoft - http://www.helixoft.com
VSdocman - Commenter and generator of class documentation for C#, VB
..NET and ASP .NET code
Author
5 Jun 2009 1:31 AM
Branco
Dennis wrote:
> 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.