-
Notifications
You must be signed in to change notification settings - Fork 0
The String Standard Library
Contains all string manipulation and regex functions for Algo. The contents of this library are automatically imported into Algo on runtime. You can call all of these without using any import statements. Don't try and import this library, as it will throw an error.
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
Returns a substring of the original string, given a start and a length.
Parameters:
Name | Description |
---|---|
base | The base string to get a substring from. |
start | The starting index (included). |
length | The length of the substring. |
Usage:
print string.substring("hello world", 2, 3); //llo
Returns a boolean, representing whether a given string ends with a substring (eg. returns true
for "does 'chocolate' end in 'ate').
Parameters:
Name | Description |
---|---|
base | The base string to check the end of. |
sub | The substring to look for at the end. |
Usage:
if (string.endsWith("qualification", "cation")) //true
{
print "\qQualification\q ends with \qcation\q";
}
Returns a boolean, representing whether a given string starts with a substring (eg. returns true
for "does 'chocolate' start with 'cho').
Parameters:
Name | Description |
---|---|
base | The base string to check the start of. |
sub | The substring to look for at the start. |
Usage:
if (string.startsWith("qualification", "qualif")) //true
{
print "\qQualification\q starts with \qqualif\q";
}
Checks whether a given string would properly evaluate to an Algo integer, returns a boolean.
Parameters:
Name | Description |
---|---|
x | The string to check. |
Usage:
let x = "3";
print string.isInteger(x); //true
Checks whether a given string would properly evaluate to an Algo floating point number, returns a boolean.
Parameters:
Name | Description |
---|---|
x | The string to check. |
Usage:
let x = "3.14159265";
print string.isFloat(x); //true
Returns the given string, but converted to be all upper case.
Parameters:
Name | Description |
---|---|
x | The string to make upper case. |
Usage:
print string.toUpper("Hello world."); //HELLO WORLD.
Returns the given string, but converted to be all lower case.
Parameters:
Name | Description |
---|---|
x | The string to make lower case. |
Usage:
print string.toLower("HeLlo WorLd."); //hello world.
Algo (c) Larry Tang, 2019.
Commercial use of Algo must include the LICENSE
file in the same directory as the executable.
Standard Library Documentation: