Skip to content

Strings

Instance methods on string values.

Methods

MethodReturnsDescription
len()intLength in bytes
upper()stringUppercase
lower()stringLowercase
trim()stringStrip whitespace
trim_left()stringStrip leading whitespace
trim_right()stringStrip trailing whitespace
contains(s)boolSubstring check
starts_with(s)boolPrefix check
ends_with(s)boolSuffix check
index_of(s)intFirst occurrence (-1 if not found)
last_index_of(s)intLast occurrence
substring(start, end)stringExtract range
replace(old, new)stringReplace all occurrences
repeat(n)stringRepeat n times
reverse()stringReverse characters
capitalize()stringFirst char uppercase
title()stringTitle case
pad_left(n, ch)stringLeft-pad to width
pad_right(n, ch)stringRight-pad to width
split(delim)[string]Split into array
count(s)intCount occurrences
to_int()intParse integer
is_alpha()intAll alphabetic (1/0)
is_digit()intAll numeric (1/0)

Examples

wyn
var s = "Hello, World!"
println(s.upper())                      // HELLO, WORLD!
println(s.lower())                      // hello, world!
println(s.contains("World").to_string()) // true
println(s.replace("World", "Wyn"))      // Hello, Wyn!
println(s.split(", ").join(" | "))      // Hello | World!

Chaining

wyn
var clean = "  HELLO  ".trim().lower().reverse()
println(clean)  // olleh

Interpolation

wyn
var name = "Wyn"
println("Hello, ${name}!")

MIT License