# 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`.

Web page: https://pseudolearn.app/en/spec/lexico/textos

> **In one sentence**
>
> 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`.

## 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: Character or string**

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.

The number of characters between the quotes decides the type, not the kind of quotes.

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

| Escape | Meaning |
| --- | --- |
| `\n` | line break |
| `\t` | tab |
| `\r` | carriage return |
| `\\` | one backslash |
| `\"` | double quote |
| `\'` | single quote |

### Program: Quotes and escapes

```pseudolearn
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**

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

*The program finishes normally.*

> **Limit**
>
> A character is a single Unicode code point, including those outside the basic plane such as a simple emoji. A grapheme made of several code points is a string. The text is kept as it is, without normalising. A text cannot span several lines: a line break is written with `\n`.

> **Common mistakes**
>
> An escape that does not exist and unclosed quotes are detected before running:
>
> ### Program: An invented escape
>
> ```pseudolearn
> Algorithm MalEscape
>   Write "a\q";
> EndAlgorithm
> ```
>
> **Diagnostics**
> - `invalidEscapeSequence` (error, 2:11): Invalid escape sequence: \q
>
> *The program finishes with an error.*
>
> ### Program: Unclosed quotes
>
> ```pseudolearn
> Algorithm SinCerrar
>   Write "hola;
> EndAlgorithm
> ```
>
> **Diagnostics**
> - `unterminatedString` (error, 2:9): Unterminated string literal
>
> *The program finishes with an error.*

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

**See also**
- [3.1 Primitive types](https://pseudolearn.app/en/spec/tipos/primitivos.md)
- [12.2 Text functions](https://pseudolearn.app/en/spec/biblioteca/texto.md)
