Section 3.4 - Character and String Literals
Sometimes a literal of a single character is needed.
A single character is represented using by enclosing it in single
quotes ('). For example, 'a' represents the lower case letter A.
This is true even if it's a single quote character, so '''
represents a single quote character.
Strings are enclosed in double quote characters (").
To include a double quote character in a string, type it twice ("")
inside the larger string.
Thus "Hello" is a string, as is "She said, ""How are you?""".
An empty string is simply written as "".
We'll find out later how to represent control characters, but
for now we'll note that C-like escape characters do not work.
You can do the same thing in Ada but in a different way, and because of
the way Ada works they aren't used as often.
Quiz:
Given the following items:
-
"Hello"
-
'''
-
"Please press ""RETURN"""
-
""
-
"wokka""
Which of the following is true?
- Items 1, 3, and 4 are string literals, item 2 is a character literal, and item 5 is neither.
- Items 1 and 4 are string literals, item 2 is a character literal, and items 3 and 5 are neither.
- They are all legal string or character literals.
You may also:
David A. Wheeler (dwheeler@ida.org)