Strings
Instance methods on string values.
Methods
| Method | Returns | Description |
|---|---|---|
len() | int | Length in bytes |
upper() | string | Uppercase |
lower() | string | Lowercase |
trim() | string | Strip whitespace |
trim_left() | string | Strip leading whitespace |
trim_right() | string | Strip trailing whitespace |
contains(s) | bool | Substring check |
starts_with(s) | bool | Prefix check |
ends_with(s) | bool | Suffix check |
index_of(s) | int | First occurrence (-1 if not found) |
last_index_of(s) | int | Last occurrence |
substring(start, end) | string | Extract range |
replace(old, new) | string | Replace all occurrences |
repeat(n) | string | Repeat n times |
reverse() | string | Reverse characters |
capitalize() | string | First char uppercase |
title() | string | Title case |
pad_left(n, ch) | string | Left-pad to width |
pad_right(n, ch) | string | Right-pad to width |
split(delim) | [string] | Split into array |
count(s) | int | Count occurrences |
to_int() | int | Parse integer |
is_alpha() | int | All alphabetic (1/0) |
is_digit() | int | All 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) // ollehInterpolation
wyn
var name = "Wyn"
println("Hello, ${name}!")