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 hold an apostrophe as it is. To put a double quote inside a string, write it twice:
A string can span lines. Every line ending inside it reads as 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 displays 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. Reverse, for one:
= compares two strings one character at a time. ≡ compares them whole:
Index of, dyadic ⍳, finds where each character first appears. A missing character gets the length of the string:
Find, ⍷, marks each position where a pattern starts:
< sorts characters by code point:
Adding an integer to a character moves it along the Unicode code points. Subtracting one character from another gives the distance between them:
The order comparisons, such as <, take only numbers. Grade is the way to sort text.
System functions cover the rest of text handling. •ucs converts between characters and code points:
•c changes case:
$a and $d hold the alphabet and the digits. Membership, ∊, then tests which characters are digits:
⍕ formats any value as text:
Regular expressions covers matching patterns in text with •r.