This documentation is archived and is not being maintained.

2.4.4 String Literals

Visual Studio .NET 2003

A string literal is a sequence of zero or more Unicode characters beginning and ending with an ASCII double-quote character, a Unicode left double-quote character, or a Unicode right double-quote character. Within a string, a sequence of two double-quote characters is an escape sequence representing a double quote in the string. A string constant is of the String type.

Imports System

Module Test
    Sub Main()
        ' This prints out: ".

        ' This prints out: a"b.

        ' This causes a compile error due to mismatched double-quotes.
    End Sub
End Module

Each string literal does not necessarily result in a new string instance. When two or more string literals that are equivalent according to the string equality operator using binary comparison semantics appear in the same program, these string literals refer to the same string instance. For instance, the output of the following program is True because the two literals refer to the same string instance.

Imports System

Module Test
    Sub Main()
        Dim a As Object = "hello"
        Dim b As Object = "hello"
        Console.WriteLine(a Is b)
    End Sub
End Module
StringLiteral ::=
   DoubleQuoteCharacter [ StringCharacter+ ] DoubleQuoteCharacter
DoubleQuoteCharacter ::=
   " |
   < Unicode left double-quote character (0x201C) > |
   < Unicode right double-quote character (0x201D) >
StringCharacter ::= 
   < Character except for DoubleQuoteCharacter > |
   DoubleQuoteCharacter DoubleQuoteCharacter

See Also

2.4.1 Boolean Literals | 2.4.2 Integer Literals | 2.4.3 Floating-Point Literals | 2.4.5 Character Literals | 2.4.6 Date Literals | 2.4.7 Nothing | 2.4 Literals | String Data Type (Visual Basic Language Reference) | Strings (Visual Basic Language Concepts)