-
Notifications
You must be signed in to change notification settings - Fork 0
The String Standard Library
C272 edited this page Aug 31, 2019
·
9 revisions
Contains all string manipulation and regex functions for Algo.
Splits a string into its individual characters, returned in a list.
Parameters:
| Name | Description |
|---|---|
| x | The string to split into characters. |
Usage:
let x = "hello";
print string.toChars(x); //["h", "e", "l", "l", "o"]
Checks whether a substring is contained within a string.
Parameters:
| Name | Description |
|---|---|
| base | The base string to check for substrings in. |
| sub | The substring to check for. |
Usage:
if (string.contains("foo", "oo"))
{
print "hello"; //this is printed
}
Splits a given string using the provided delimiter, returning a list. The list is always at least one value long.
Parameters:
| Name | Description |
|---|---|
| str | The string to split into a list. |
| delim | The delimiter to split by. |
Usage:
let x = "This! is! a! string";
print string.split(x, "! "); //["This", "is", "a", "string"]
Replace any occurences of a substring with another string (eg. replace "a" with "b" in "aaa" will result in "bbb").
Parameters:
| Name | Description |
|---|---|
| base | The base string to replace in. |
| old | The substring to replace. |
| new | The new string to replace the old one with. |
Usage:
let x = "hello world!";
x = string.replace(x, "hello", "eyo");
print x; //eyo world!
Reverses the given string, and returns it.
Parameters:
| Name | Description |
|---|---|
| x | The string to reverse. |
Usage:
print string.reverse("wahoo"); //oohaw
Algo (c) Larry Tang, 2019.
Commercial use of Algo must include the LICENSE file in the same directory as the executable.
Standard Library Documentation: