---
title: Characters and strings
description: 'Characters, strings and vectors of strings: writing them, quoting, display,
  and the functions that work on text'
---
A character is an [atom](terms.md#term-atom), like a number, written in single quotes. A string is a vector of any number of characters, even one or none, written in double quotes. `''` also gives the empty string:

```bpl
ρ'a'               ⍝ ⍬ₓ
ρ"a"               ⍝ [1]ₓ
ρ"abc"             ⍝ [3]ₓ
ρ''                ⍝ [0]ₓ
```

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Quotes inside text

The character literal for a single quote is `'''`. A string can contain an unescaped single quote. To put a double quote inside a string, write it twice:

```bpl
•ucs '''           ⍝ 39ₓ
≢"can't"           ⍝ 5ₓ
≢"say ""hi"""      ⍝ 8ₓ
```

## Text across lines

A string can span lines. Every line ending inside it becomes one newline, and its indentation stays as written. The REPL waits for the closing quote.

```bpl
poem←"Roses are red,
  violets are blue"
≢poem
poem
```

```output
33ₓ
"Roses are red,
  violets are blue"
```

## Strands of text

Literals separated by spaces form one vector, called a [strand](terms.md#term-strand), whether they are characters or strings:

```bpl
'a' 'b' 'c'        ⍝ "abc"
≢"one" "three"     ⍝ 2ₓ
≢¨"one" "three"    ⍝ [3 5]ₓ
```

Keys are written as a vector of strings, as in `"x" "y":1 2`. [Axis keys](keyed.md) covers keyed arrays.

## How text is displayed

On its own, a string is displayed as plain text and a character matrix as lines of text. Inside a larger array, strings keep their double quotes and characters their single quotes. In the REPL:

```text
      "abc"
abc
      2 3ρ"abcdef"
abc
def
      ⊂"ab"
⊂"ab"
      "abc",⊂"de"
'a' 'b' 'c' "de"
```

## Working with text

Functions that work on vectors work on strings too, such as [`⌽`](https://bpl.fast.ai//glyphs/circle-stile.html):

```bpl
⌽"abc"
```

```output
"cba"
```

[`=`](https://bpl.fast.ai//glyphs/equals.html) compares two strings one character at a time. [`≡`](https://bpl.fast.ai//glyphs/equal-underbar.html) compares them as a whole:

```bpl
"abc"="abd"
"abc"≡"abd"
```

```output
$t $t $f
$f
```

[`ι`](https://bpl.fast.ai//glyphs/iota.html) finds the first position in the left string of each character in the right string. For a character not in the left string, [`ι`](https://bpl.fast.ai//glyphs/iota.html) gives the length of the left string:

```bpl
"abc"ι"cz"
```

```output
[2 3]ₓ
```

Find [`⍷`](https://bpl.fast.ai//glyphs/epsilon-underbar.html) marks each position where a pattern starts:

```bpl
"an"⍷"banana"
```

```output
$f $t $f $t $f $f
```

[`<`](https://bpl.fast.ai//glyphs/less-than.html) sorts characters by code point:

```bpl
<"bca"
```

```output
"abc"
```

Adding a whole number to a character moves it along the Unicode code points. Subtracting one character from another gives the distance between their code points:

```bpl
'a'+3
'a'+ι3ₓ
'd'-'a'
```

```output
'd'
"abc"
3ₓ
```

The order comparisons, such as [`<`](https://bpl.fast.ai//glyphs/less-than.html), compare characters by code point. A number is less than any character.

[System functions](system-functions.md) cover the rest of text handling. `•ucs` converts between characters and code points:

```bpl
•ucs "ABC"
```

```output
[65 66 67]ₓ
```

`•c` changes case:

```bpl
•c "Hello"
```

```output
"hello"
```

`$a` holds the uppercase alphabet, and `$d` holds the digits. [`∊`](https://bpl.fast.ai//glyphs/epsilon.html) tests which characters are in `$d`:

```bpl
"a2b"∊$d
```

```output
$f $t $f
```

[`⍕`](https://bpl.fast.ai//glyphs/thorn.html) formats any value as text:

```bpl
"Total: ",⍕+/1.5 2
```

```output
"Total: 3.5"
```

[Regular expressions](regex.md) covers matching patterns in text with `•r`.
