Skip to content

SpecificationII · Lexical structure

2.7

Text and character literals

A text goes between double or single quotes; if it contains exactly one character it is a Character, and in any other case it is a String.

Markdown version

2.7.1 How it works

Texts are written between quotes. Double quotes "…" and single quotes '…' mean the same. What decides the type is how many characters are inside:

  • Exactly one: it is a character (Character).
  • None, or more than one: it is a string (String).
Figure 2.7-1.The number of characters between the quotes decides the type, not the kind of quotes.

At the top, A between single quotes and between double quotes both lead to the Character type. Below, empty quotes and a two-letter text lead to the String type.

Inside a text, the backslash starts an escape sequence to write special characters:

EscapeMeaning
\nline break
\ttab
\rcarriage return
\\one backslash
\"double quote
\'single quote

ProgramQuotes and escapes

Algorithm Escapes
  Define inicial As Character <- 'A';
  Write "Primera línea\nSegunda línea";
  Write "Dijo: \"hola\"";
  Write 'Comillas simples', " y la inicial ", inicial;
EndAlgorithm

Output

Primera línea
Segunda línea
Dijo: "hola"
Comillas simples y la inicial A

The program finishes normally.

In short

  • Double or single quotes: they mean the same.
  • One character inside: Character. Zero or several: String.
  • Escapes: \n, \t, \r, \\, \" and \'.