Value methods

Langoost values carry built-in methods, called with dot syntax — value.method(args). This page lists the methods on each primitive type. (Array methods are covered in full on the arrays page.)

String methods

let s = "  Hello, World  "
println(s.trim().lower())      // "hello, world"
MethodDescription
lenLength in bytes
upper() / lower()Change case
trim([cutset]) / trimLeft([cutset]) / trimRight([cutset])Trim whitespace or a cutset
split(sep)Split into a string[]
contains(sub)Whether sub occurs
hasPrefix(p) / hasSuffix(s)Prefix / suffix test
startsWith(p) / endsWith(s)Aliases for the above
replace(old, new)Replace all occurrences
replaceFirst(old, new)Replace the first occurrence
indexOf(sub) / lastIndexOf(sub)First / last index (−1 if absent)
slice(start, end)Substring [start, end) (negative indices allowed)
repeat(n)Repeat n times
padLeft(width, fill?) / padRight(width, fill?)Pad to a width
format(...args)sprintf-style (%s, %d, %f, %v)
toInt() / toFloat()Parse to a number (0 on failure)
isEmpty()Whether the string is empty

Array methods

Arrays support push, pop, first, last, slice, contains, indexOf, join, reverse, sort, flatten, and the higher-order map, filter, reduce, forEach, find, findIndex, every, and some. See arrays for signatures and examples.

Number methods

println((255).toBase(16))      // "ff"
println((-3).abs())            // 3
println((3.9).toInt())         // 3

Int: toString(), toFloat(), toBase(base), abs() Float: toString(), toInt() (truncates), abs() Bool: toString()

Many of these overlap with the global built-ins (toString, toInt, toFloat) and the strings and types modules — use whichever reads best.