String Module Documentation
IMPORT MOD "STRING"
This module provides various string manipulation functions that allow for conversion, splitting, transformation, and inspection of strings.
Table of Contents
Functions
TO_NUMBER
Converts a string to a number (f64). Returns NULL if the conversion is not possible.
Parameters:
raw: StringThe string to convert.
Returns:
Number: The converted number,NULLIf the conversion fails.
Example Usage:
number <- TO_NUMBER("123.45")
IF (number == NULL) {
DISPLAY("Conversion failed.")
}
TO_BOOL
Converts a string to a boolean. Returns NULL if the conversion is not possible.
Parameters:
raw: StringThe string to convert.
Returns:
Bool: The converted boolean,NULLIf the conversion fails.
Example Usage:
boolean <- TO_BOOL("TRUE") // you can also use "true" here
IF (boolean != NULL AND boolean == TRUE) {
DISPLAY("It's true!")
}
SPLIT
Splits a string into a list of strings based on a pattern.
Parameters:
raw: StringThe string to split.pattern: StringThe delimiter used to split the string.
Returns:
List: A list of strings obtained by splitting the original string.
Example Usage:
parts <- SPLIT("apple,banana,orange", ",")
FOR EACH item IN parts {
DISPLAY(item)
}
// apple
// banana
// orange
TO_UPPER
Converts a string to uppercase.
Parameters:
raw: StringThe string to convert.
Returns:
String: The converted uppercase string.
Example Usage:
upper_case <- TO_UPPER("hello")
DISPLAY(upper_case) // "HELLO"
TO_LOWER
Converts a string to lowercase.
Parameters:
raw: StringThe string to convert.
Returns:
String: The converted lowercase string.
Example Usage:
lower_case <- TO_LOWER("HELLO")
DISPLAY(lower_case) // "hello"
TRIM
Removes leading and trailing whitespace from a string.
Parameters:
raw: StringThe string to trim.
Returns:
String: The trimmed string.
Example Usage:
trimmed <- TRIM(" hello ")
DISPLAY(trimmed) // "hello"
CONTAINS
Checks if a string contains a given substring.
Parameters:
raw: StringThe string to search.pattern: StringThe substring to search for.
Returns:
Bool:TRUEif the substring is found,FALSEotherwise.
Example Usage:
contains <- CONTAINS("hello world", "world")
IF (contains) {
DISPLAY("Found it!")
}
REPLACE
Replaces all occurrences of a substring with another substring.
Parameters:
raw: StringThe string to modify.from: StringThe substring to replace.to: StringThe substring to replace with.
Returns:
String: The modified string with replacements.
Example Usage:
replaced <- REPLACE("hello world", "world", "everyone")
DISPLAY(replaced) // "hello everyone"
STARTS_WITH
Checks if a string starts with a given prefix.
Parameters:
raw: StringThe string to check.prefix: StringThe prefix to check for.
Returns:
Bool:TRUEif the string starts with the prefix,FALSEotherwise.
Example Usage:
starts <- STARTS_WITH("hello", "he")
IF (starts) {
DISPLAY("Starts with 'he'")
}
ENDS_WITH
Checks if a string ends with a given suffix.
Parameters:
raw: StringThe string to check.suffix: StringThe suffix to check for.
Returns:
Bool:TRUEif the string ends with the suffix,FALSEotherwise.
Example Usage:
ends <- ENDS_WITH("hello", "lo")
IF (ends) {
DISPLAY("Ends with 'lo'")
}
JOIN
Joins a list of strings into a single string, separated by a given separator.
Parameters:
list: ListThe list of strings to join.separator: StringThe separator to use between elements.
Returns:
String: The joined string.
Example Usage:
joined <- JOIN(["apple", "banana", "orange"], ", ")
DISPLAY(joined) // "apple, banana, orange"
SUBSTRING
Extracts a substring from a string, starting at a given position and of a specified length.
Parameters:
raw: StringThe original string.start: NumberThe starting index (1-based).length: NumberThe length of the substring.
Returns:
String: The extracted substring.
Example Usage:
substring <- SUBSTRING("hello world", 1, 4)
DISPLAY(substring) // ello
TO_CHAR_ARRAY
Converts a string into a list of single-character strings.
Parameters:
raw: StringThe string to convert.
Returns:
List: A list where each element is a single-character string.
Example Usage:
char_array <- TO_CHAR_ARRAY("hello")
FOR EACH char in char_array {
DISPLAY(char)
}
// h
// e
// l
// l
// o