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:

  1. "Hello"
  2. '''
  3. "Please press ""RETURN"""
  4. ""
  5. "wokka""

Which of the following is true?

  1. Items 1, 3, and 4 are string literals, item 2 is a character literal, and item 5 is neither.
  2. Items 1 and 4 are string literals, item 2 is a character literal, and items 3 and 5 are neither.
  3. They are all legal string or character literals.

You may also:

PREVIOUS Go back to the previous section

NEXT     Skip to the next section

OUTLINE  Go up to lesson 3 outline

David A. Wheeler (dwheeler@dwheeler.com)

The master copy of this file is at "http://www.adahome.com/Tutorials/Lovelace/s3sf.htm".