poem←"Roses are red,
violets are blue"
≢poem
poem33ₓ
"Roses are red,
violets are blue"
A character is an 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:
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:
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.
Literals separated by spaces form one vector, called a strand, whether they are characters or strings:
Keys are written as a vector of strings, as in "x" "y":1 2. Axis keys covers keyed arrays.
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:
"abc"
abc
2 3ρ"abcdef"
abc
def
⊂"ab"
⊂"ab"
"abc",⊂"de"
'a' 'b' 'c' "de"
Functions that work on vectors work on strings too, such as ⌽:
= compares two strings one character at a time. ≡ compares them as a whole:
ι finds the first position in the left string of each character in the right string. For a character not in the left string, ι gives the length of the left string:
Find ⍷ marks each position where a pattern starts:
< sorts characters by code point:
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:
The order comparisons, such as <, compare characters by code point. A number is less than any character.
System functions cover the rest of text handling. •ucs converts between characters and code points:
•c changes case:
$a holds the uppercase alphabet, and $d holds the digits. ∊ tests which characters are in $d:
⍕ formats any value as text:
Regular expressions covers matching patterns in text with •r.