Monday, October 06, 2008

Have a long literals string in VB? Forget the underscore and just use VB9’s XML Literals

Goto 100 - Development with Visual Basic - Long strings in Visual Basic 2008

“I suspect everyone already knew this – but for me it was shiny and new :-) XML Literals do not require line continuation characters, hence rather than this:

 image

you can create a really long string using an XML Literal:

image

Note: the whitespace is maintained.” [Post leached in full]

This tip made me laugh as I just thought it was just too cool… And until we get rid of the line continuation character (in VB10, I hope), I think I might be able to use this a trick.

But note the note. Maintained whitespace means the above message would look like;

 image

So if you use this trick, make sure you understand this…

4 comments:

  1. Dude, that's one of the coolest trick I've seen - made my day when I saw that (and I have to use it for an example i'm making).

    Very cool :).

    ReplyDelete
  2. It is still a patch to a really really weak language. I mean, why not just get rid of the tags and underscores once and for all. Let the carriage return be the end of the line markup ... damn!

    ReplyDelete
  3. This is fantastic!!! Great tip. I think this improvement would work to avoid the white space issue:

    Dim myString As String =
    some
    more
    text.
    .Value

    myString now holds the value "some more text."

    ReplyDelete
  4. OK that last post should have tags around the values. I guess Blogger can't handle angle brackets in the comments.

    ReplyDelete

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...