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
| Parameter | Type | Description |
|---|---|---|
string | str | String to find length of |
Example
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
| Parameter | Type | Description |
|---|---|---|
string | str | String to slice |
start | i64 | Starting index (inclusive) |
end | i64 | Ending index (inclusive) |
Example
assert('banana'.sub(2, 4) == nan.str());string.repeat
string.repeat(string: str, count: i64) -> str
Repeats a string count amount of times
Arguments
| Parameter | Type | Description |
|---|---|---|
string | str | String to repeat |
count | i64 | Amount of times to repeat string |
Example
assert('a'.repeat(5) == 'aaaaa');string.reverse
string.reverse(string: str) -> str
Reverses a string character by character
Arguments
| Parameter | Type | Description |
|---|---|---|
string | str | String to reverse |
Example
val a = 'tacocat';
assert(a.reverse() == a);string.join
string.join(strings: obj) -> str
Joins an array of strings into a single str
Arguments
| Parameter | Type | Description |
|---|---|---|
strings | obj | An array of strings |
separator | `obj | nil` |
Example
{'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
| Parameter | Type | Description |
|---|---|---|
string | str | String to split apart |
delim | str | Separator to split at |
Example
'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
| Parameter | Type | Description |
|---|---|---|
string | str | String to convert |
Example
assert('A'.ord() == 65);string.upper
string.upper(string: str) -> str
Creates a new copy of a string in all uppercase letters
Arguments
| Parameter | Type | Description |
|---|---|---|
string | str | String to transform |
string.lower
string.lower(string: str) -> str
Creates a new copy of a string in all lowercase letters
Arguments
| Parameter | Type | Description |
|---|---|---|
string | str | String to transform |
