I suggest you ...

Line continuation in strings

Would be great to have the equivalent of @" some string " in c# in order to do line continuation in VB without the cumbersome " & _.
That would be particularly useful when writing SQL Statements.
Something like:

SqlQry = @" SELECT
Col1,
Col2,
Col3
FROM TableName; "

15 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    CharlesCharles shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
    completed  ·  Visual Studio teamAdminVisual Studio team (Product Team, Microsoft) responded  · 

    Hey everyone,

    If you hadn’t heard already last week at BUILD we announced the PUBLIC release of a Preview of the next version of the Visual Basic language and code editing experience powered by “Roslyn”. You can download this preview and install it on top of Visual Studio 2013 today!

    I’m excited to let you know that included in this is a preview of support for multiline string literals in Visual Basic:

    Dim query =
    SELECT
    Col1,
    Col2
    FROM Table
    WHERE
    Col1 = Col2”

    You can read about it more here: http://www.codeplex.com/Download?ProjectName=roslyn&DownloadId=824695

    Download the End User Preview @ http://msdn.microsoft.com/en-US/vstudio/roslyn

    I encourage you all to download it, try it out, and send us your feedback.

    Regards,

    Anthony D. Green, Program Manager, Visual Basic & C# Languages Team

    8 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Robert EinhornRobert Einhorn commented  ·   ·  Flag as inappropriate

        Some multi-line string literal examples with the simplified syntax.

        s = @"
             '╔╗─╔╗╔══╗─────────╔╗
             '║╚╦╝║║╔╗║──╔═╦╗╔═╗║╚╗
             '╚╗║╔╝║╔╗║╔╗║║║║║╩╣║╔╣
             '─╚═╝─╚══╝╚╝╚╩═╝╚═╝╚═╝
             "

        - comment and string literal using:
        s = "'this is not a comment"
        s = @"this
             'is
             'also
             'not
             'a
             'comment
             "

        - the following lines are commented out:
        's = "abc"
        's = @"a
        '     'b
        '     'c
        '     "

        - the following examples are equivalents without syntax error:
        s = @"a
             'b
             'c
             "

        s = @"a
        'b
        'c
        "

        s = @"a
              'b
               'c
                "

        Result:
        a
        b
        c

        - well formattable source code:
        s = "abc" + @"
            'd
            'e
            'f
            'g
            " + "hij"

        Result:
        abc
        d
        e
        f
        ghij

        - formatted text example:
        Console.Write(@"First Name: {0}
                       'Last Name:  {1}
                       'e-mail:     {2}
                       ", sFirstName, sLastName, sEmail)

        - SQL statement with single and double quote marks:
        query = @"INSERT INTO Users (Message) 
                 'VALUES ('"Hello"');
                 "

        - HTML with JavaScript source code:
        HTML_JavaScript = @"<html>
                           '   <body>
                           '      <h1>
                           '         HTML and JavaScript source code 
                           '         in VB.net source code
                           '      </h1>
                           '      <p>
                           '         "double quotation"<br>
                           '         'single quotation'
                           '      </p>
                           '      <script type="text/javascript">
                           '         var text1="Hello World!";
                           '         var text2='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
                           '         var text3='this isn\'t a double quoted string literal';
                           '         
                           '         document.write(text1 + "<br>")
                           '         document.write(text2 + "<br>")
                           '         document.write(text3 + "<br>")
                           '      </script>
                           '   </body>
                           '</html>
                           "

        --------------

        MsgBox(@"I think the multi-line string literal would be useful.
                'Thanks
                'Robert
                ")

      • Robert EinhornRobert Einhorn commented  ·   ·  Flag as inappropriate

        Improving my idea...
        I think the number of the newlines is not absolutely clear in my previous two ideas.
        So, I would like to suggest a new simplified syntax:

        - well formattable code:
        SqlQry = @"SELECT
                  'Col1,
                  'Col2,
                  'Col3
                  'FROM TableName;
                  "

        Result:
        SELECT
        Col1,
        Col2,
        Col3
        FROM TableName;

        - there is no escaping, any text can be used:
        s = @"this is a quotation mark"
             'and this is an other quotation mark"
             "

        Result:
        this is a quotation mark"
        and this is an other quotation mark"

        --------------

        Rules:
        - the @" characters are the opening symbol of the multi-line string literal
        - any text can be used after the opening symbol
        - the closing symbol is the double-quote-mark (") at the beginning of a new line
        - optional white spaces can be used before the closing symbol (")
        - between the opening and the closing symbols, the lines must be started with single-quote-marks
        - the single-quote-marks REPRESENT THE NEWLINE characters (CrLf) in the multi-line text
        - before the single-quote-marks, only optional white spaces can be used
        - after the single-quote-marks, any text can be used

        Remark:
        The single-quote-mark as a syntax symbol is not important.
        Other character can be imaginable instead of it (e.g: ` backtick, etc.).
        In my opinion the single-quote-mark is appropriate to sign a text in the source code and the comment out texteditor feature (Ctrl+E,C) also may be useful in this context.

        The @ character as a syntax symbol is also not important.
        Other character also can be imaginable instead of it (e.g. $ or # etc.).

        Some syntax error examples to understand the rules of the multi-line string literal:
        - single-quote-mark is missing:
        s = @"a
             b
             'c
             'd
             "

        s = @"a
             'b
             'c
             d"

        - the closing double-quote-mark is missing:
        s = @"a
             'b
             'c
             'd"

        --------------

        Text Editor supports:
        In the following examples, the pipe character ( | ) represents the cursor (beam).
        - auto completion after typing an opening symbol @"

        s = @"|

          ↓

        s = @"|
             "

        - auto completion after a pressed Enter key when the cursor ( | ) is inside the multi-line string literal:

        s = @"abc|
             "

          ↓

        s = @"abc
             '|
             "

        - auto completion after a pasting when the cursor ( | ) is inside the multi-line string literal:

        s = @"---a---
             '---b-|--
             '---c---
             "

          ↓

        s = @"---a---
             '---b-CLIPBOARD TEXT line 1
             'CLIPBOARD TEXT line 2
             'CLIPBOARD TEXT line 3|--
             '---c---"
             "

      • Robert EinhornRobert Einhorn commented  ·   ·  Flag as inappropriate

        @Anthony:
        Your syntax is a very good idea to implement an easy to format multi-line string literal but unfortunately the double-quotation marks still cannot be used freely.

        - well formattable source code:
        SqlQry = "SELECT
                 "Col1,
                 "Col2,
                 "Col3
                 "FROM TableName;"

        RESULT:
        SELECT
        Col1,
        Col2,
        Col3
        FROM TableName;

        - but escaping quotes are still necessary:
        s = "this is a quotation mark""
            "and this is an other quotation mark"""

        RESULT:
        this is a quotation mark"
        and this is an other quotation mark"

        --------------

        I have two kind of similar ideas also for a well formattable multi-line string literal.

        1. idea by single-quotes:
        SqlQry = @"'SELECT
                   'Col1,
                   'Col2,
                   'Col3
                   'FROM TableName;
                  "

        s = @"
             'this is a quotation mark"
             'and this is an other quotation mark"
             "

        Advantages:
        - there is no escaping, any text can be used freely without restrictions (of course only after the single-quotes)
        - currently there is a support to insert single-quotes before the selected text-lines with the COMMENT OUT toolbar button

        --------------

        2. idea by double-quotes:
        SqlQry = @"SELECT
                  "Col1,
                  "Col2,
                  "Col3
                  "FROM TableName;
                 @"

        s = @"this is a quotation mark"
             "and this is an other quotation mark"
        @"

        Advantages:
        - there is no escaping, any text can be used freely without restrictions after the double-quotes

        --------------

        @Anthony:
        "...but made it harder to just paste a block of text into the editor."

        I can imagine IDE supports for multi-line string literal.
        For your idea:
        - auto completion after a pressed Enter key when the cursor ( | char) is between the opening and the closing double-quotes:

        s = "|"

          |
          V

        s = "|
            ""

        - auto completion after a pasting when the cursor ( | char) is inside a multi-line string literal:

        s = "---a---
            "---b-|--
            "---c---"

          |
          V

        s = "---a---
            "---b-CLIPBOARD TEXT 1. line
            "CLIPBOARD TEXT 2. line
            "CLIPBOARD TEXT 3. line|--
            "---c---"

        Of course, similar auto completions are also imaginable for my ideas.
        In addition, I would suggest a little different background color for the multi-line string literals to appear space characters at the end of the lines what are invisible with the default background color.

      • Robert EinhornRobert Einhorn commented  ·   ·  Flag as inappropriate

        @Charles:
        I would not suggest either the C# verbatim string literal or the VB.net XML literal as multi-line string literal in VB.net.
        There are some restrictions and problems with these features.

        - For example, the following C# code is very badly formatted and the double-quotation mark cannot be used freely in the text, it can be used only by escaping quote:

        public string TextLines()
        {
            if(true)
            {
                if(true)
                {
                    return @"this is a quotation mark""
        and this is an other quotation mark""";
                }
            }
        }

        RESULT:
        this is a quotation mark"
        and this is an other quotation mark"

        - Unfortunately, we get a bad result with a "well" formatted code:
        public string TextLines()
        {
            if(true)
            {
                if(true)
                {
                    return @"this is a quotation mark""
                             and this is an other quotation mark""";
                }
            }
        }

      • Reed Kimble (VB MVP)Reed Kimble (VB MVP) commented  ·   ·  Flag as inappropriate

        Sorry, I should add that granted, this does not address the query issue where the line breaks are desirable for code formatting purposes, not for output purposes. Perhaps I should submit CCSTR as its own idea?

      • Reed Kimble (VB MVP)Reed Kimble (VB MVP) commented  ·   ·  Flag as inappropriate

        Would it be possible to just get a new global method like "CCSTR()" that interprets "expression" the same as C# would do with a regular string?

        This is my current solution in my own code; a clunky conversion routine I reuse often. But it would be great if I could just have the same functionality already implemented for C#, or at least a framework-native equivalent that was faster than doing my own string replacement on escape sequences.

        I would actually prefer this to the in-line string line-breaks because they make the code messy to read (to my eyes) in any of the shown formats. I'd rather just call a special method and then use a regular markup string when I know I need line breaks in my literal.

      • CharlesCharles commented  ·   ·  Flag as inappropriate

        Couldn't agree more. The trick I am currently using is to write my query within xml litteral, but that doesn't allow angle brackets, which is a problem for SQL queries:

        Dim SqlQry = <Q>

        SELECT
        Col1,
        Col2,
        Col3
        FROM TableName;

        </Q>.Value

      Feedback and Knowledge Base