Skip to content

The String Standard Library

C272 edited this page Aug 31, 2019 · 9 revisions

Contains all string manipulation and regex functions for Algo.


string.toChars(x)

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"]

string.contains(base, sub)

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
}

string.split(str, delim)

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"]

string.replace(base, old, new)

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!

string.reverse(x)

Reverses the given string, and returns it.

Parameters:

Name Description
x The string to reverse.

Usage:

print string.reverse("wahoo"); //oohaw

Standard Library Documentation:

Clone this wiki locally