Standard library · Strings and characters
- The language
- Agents and tools
- Model providers
- The Anthropic API
- Talking agents
- Standard library
- Glossary
- Package docs
- Telemetry
- Robots
- Servers
- Deploying
- tin.ad
- The tin command
- How it works
On this page
Strings and characters
Strings are immutable UTF-8. Positions and len count bytes, so a character outside ASCII takes more than one. A char is one Unicode code point.
Example
let line = " name: Ada Lovelace "
let parts = line.trim().split(": ")
print(parts[1].upper())
print(parts[1].split(" ").map(w => w.slice(0, 1)).join("."))
print("{parts[0].padRight(8, ".")}{parts[1].len}")
print(parseInt("42").or(0) + 1) ADA LOVELACE
A.L
name....12
43 All 29 symbols
string.byteAtstring.slicestring.charAtstring.charsfromCharschar.isDigitchar.isLetterchar.isSpacechar.isUpperchar.isLowerchar.upperchar.lowerchar.comparestring.indexOfstring.containsstring.startsWithstring.endsWithstring.isEmptystring.splitstring.trimstring.upperstring.lowerstring.repeatstring.replacestring.padLeftstring.padRightjoinparseIntparseFloat
string.byteAt
fn string.byteAt(s: string, i: int): int The byte at position i, from 0 to 255. Panics if i is out of range.
string.slice
fn string.slice(s: string, from: int, to: int): string The bytes from `from` up to, but not including, `to`. Positions past either end are clamped.
string.charAt
fn string.charAt(s: string, i: int): string The one-byte string at position i, or "" past the end.
string.chars
fn string.chars(s: string): char[] The characters, decoded from UTF-8: "añ".chars() is ['a', 'ñ'].
fromChars
fn fromChars(cs: char[]): string A string made of these characters: fromChars(['h', 'i']) is "hi".
char.isDigit
fn char.isDigit(c: char): bool No summary yet; the signature is the whole description.
char.isLetter
fn char.isLetter(c: char): bool ASCII a-z and A-Z, and any character outside ASCII that is not a space.
char.isSpace
fn char.isSpace(c: char): bool No summary yet; the signature is the whole description.
char.isUpper
fn char.isUpper(c: char): bool No summary yet; the signature is the whole description.
char.isLower
fn char.isLower(c: char): bool No summary yet; the signature is the whole description.
char.upper
fn char.upper(c: char): char ASCII upper case; other characters stay as they are.
char.lower
fn char.lower(c: char): char ASCII lower case; other characters stay as they are.
char.compare
fn char.compare(a: char, b: char): int No summary yet; the signature is the whole description.
string.indexOf
fn string.indexOf(s: string, sub: string): int Where sub first occurs, or -1 if it does not.
string.contains
fn string.contains(s: string, sub: string): bool Whether sub occurs anywhere in s.
string.startsWith
fn string.startsWith(s: string, prefix: string): bool Whether s begins with prefix.
string.endsWith
fn string.endsWith(s: string, suffix: string): bool Whether s ends with suffix.
string.isEmpty
fn string.isEmpty(s: string): bool Whether s has no bytes.
string.split
fn string.split(s: string, sep: string): string[] The pieces of s between occurrences of sep. An empty sep splits into single bytes.
string.trim
fn string.trim(s: string): string s without spaces, tabs and line breaks at either end.
string.upper
fn string.upper(s: string): string s with ASCII letters in upper case. Other characters are unchanged.
string.lower
fn string.lower(s: string): string s with ASCII letters in lower case. Other characters are unchanged.
string.repeat
fn string.repeat(s: string, times: int): string s repeated `times` times.
string.replace
fn string.replace(s: string, from: string, to: string): string s with every occurrence of `from` replaced by `to`.
string.padLeft
fn string.padLeft(s: string, width: int, fill: string): string s with `fill` added on the left until it is at least `width` bytes.
string.padRight
fn string.padRight(s: string, width: int, fill: string): string s with `fill` added on the right until it is at least `width` bytes.
join
fn join(parts: string[], sep: string): string The strings of `parts` with `sep` between them.
parseInt
fn parseInt(s: string): Option<int> The integer written in s (decimal, with an optional sign), or None if s is anything else.
parseFloat
fn parseFloat(s: string): Option<float> The number written in s, or None.