Skip to main content

2.6 String Literals

danger

This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue

1

[A string_literal is formed by a sequence of graphic characters (possibly none) enclosed between two quotation marks used as string brackets. They are used to represent operator_symbols (see 6.1), values of a string type (see 4.2), and array subaggregates (see 4.3.3). ]

Syntax

2

string_literal ::= "{string_element}"

3

string_element ::= "" | non_quotation_mark_graphic_character

4

A string_element is either a pair of quotation marks (""), or a single graphic_character other than a quotation mark.

Static Semantics

5

The sequence of characters of a string_literal is formed from the sequence of string_elements between the bracketing quotation marks, in the given order, with a string_element that is "" becoming a single quotation mark in the sequence of characters, and any other string_element being reproduced in the sequence.

6

A null string literal is a string_literal with no string_elements between the quotation marks.

7

NOTE 1 An end of line cannot appear in a string_literal.

7.1/2

NOTE 2 No transformation is performed on the sequence of characters of a string_literal.

Examples

8

Examples of string literals:

9/2

"Message of the day:" "" -- a null string literal " " "A" """" -- three string literals of length 1 "Characters such as $, %, and } are allowed in string literals" "Archimedes said ""Εύρηκα""" "Volume of cylinder (πr²h) = "

Wording Changes from Ada 83

9.a

The wording has been changed to be strictly lexical. No mention is made of string or character values, since string_literals are also used to represent operator_symbols, which don't have a defined value.

9.b

The syntax is described differently.

Wording Changes from Ada 95

9.c/2

We explicitly say that the characters of a string_literal should be used as is. In particular, no normalization or folding should be performed on a string_literal.