Need help?
Ask a question or report a problem on GitHub.
Open an issue
Working with text
Measure, change, search, split, and join text with plain words.
String Length
Otter
say length of name
Example:
Otter
name is "Jeff" say length of name
Output:
Output
4
Uppercase and Lowercase
Otter
say uppercase of name say lowercase of name
Example:
Otter
name is "Jeff" say uppercase of name say lowercase of name
Output:
Output
JEFF jeff
These operations return new values.
They do not automatically modify the original variable.
Contains
Strings can be checked for text:
Otter
if name contains "Jeff" say "Found Jeff." .
Collections can be checked for an item:
Otter
games are "Zelda" "Metroid" "Mario" . if games contains "Zelda" say "Zelda is in the list." .
The parser/runtime determines whether the target is text or a collection.
Starts With
Otter
if name starts with "J" say "Starts with J." .
Ends With
Otter
if name ends with "rey" say "Ends with rey." .
Split Text
Otter
split "red,green,blue" by "," into colors
This creates a list.
Equivalent example using a variable:
Otter
text is "red,green,blue" split text by "," into colors
Join Text
Otter
join colors with ", " into text
Example:
Otter
colors are "red" "green" "blue" . join colors with " | " into text say text
Output:
Output
red | green | blue
Special characters in text
Text goes between double quotes on one line. A backslash starts an escape, and Otter understands exactly four: \n is a new line, \t is a tab, \\ is one backslash, and \" is a double quote inside the text. There is no \r. Any other backslash is kept as it is written, so \q stays \q.
Otter
say "one\ttwo" say "line one\nline two" say "She said \"hi\"" say "a backslash: \\" say "C:\\new\\table" say "C:/new/table"
Output:
Output
one two line one line two She said "hi" a backslash: \ C:\new\table C:/new/table
Windows paths: a single backslash before n or t becomes a new line or a tab, so "C:\new\table" is really C:, a new line, ew, a tab and able. Write "C:\\new\\table" with doubled backslashes, or use forward slashes, "C:/new/table", which Windows also accepts.