Skip to content

String Module

This module provides functions for manipulating str types. Note that strings in solus can be concatenated using the same + operator as any other value, which is why there is no string.cat(a, b)!

string.len

string.len(string: str) -> i64

Returns the length of a string in ASCII characters (utf8 coming soon!)

Arguments

ParameterTypeDescription
stringstrString to find length of

Example

solus
assert('abc'.len() == 3);

string.sub

string.sub(string: str, start: i64, end: i64) -> str

Returns a substring using the specified start and end. End must not be before start, and both indices are clamped

Arguments

ParameterTypeDescription
stringstrString to slice
starti64Starting index (inclusive)
endi64Ending index (inclusive)

Example

solus
assert('banana'.sub(2, 4) == nan.str());

string.repeat

string.repeat(string: str, count: i64) -> str

Repeats a string count amount of times

Arguments

ParameterTypeDescription
stringstrString to repeat
counti64Amount of times to repeat string

Example

solus
assert('a'.repeat(5) == 'aaaaa');

string.reverse

string.reverse(string: str) -> str

Reverses a string character by character

Arguments

ParameterTypeDescription
stringstrString to reverse

Example

solus
val a = 'tacocat';
assert(a.reverse() == a);

string.join

string.join(strings: obj) -> str

Joins an array of strings into a single str

Arguments

ParameterTypeDescription
stringsobjAn array of strings
separator`objnil`

Example

solus
{'solus', 'is', 'awesome'}.join(' ')

string.split

string.split(string: str, delim: str) -> obj

Splits a str into an array of strings separated by a delimiter. This can be used alongside obj.map to transform strings.

Arguments

ParameterTypeDescription
stringstrString to split apart
delimstrSeparator to split at

Example

solus
'hello'.split('').reverse().join() # same as string.reverse()

string.ord

string.ord(string: str) -> i64

Converts the first character of a string into its i64 representation (ASCII)

Arguments

ParameterTypeDescription
stringstrString to convert

Example

solus
assert('A'.ord() == 65);

string.upper

string.upper(string: str) -> str

Creates a new copy of a string in all uppercase letters

Arguments

ParameterTypeDescription
stringstrString to transform

string.lower

string.lower(string: str) -> str

Creates a new copy of a string in all lowercase letters

Arguments

ParameterTypeDescription
stringstrString to transform