String Functions¶
Mythradon provides a comprehensive suite of string functions designed to manipulate and analyse text data within the system. These functions facilitate complex string operations and encompass a wide range of capabilities:
- string\concatenate() - Merges several strings into one, simplifying the creation of compound text.
- string\contains() - Determines whether a string contains a specific substring, useful for content filtering or conditions.
- string\length() - Calculates the length of a string, essential for assessing text dimensions.
- string\lowerCase() - Converts all characters in a string to lowercase, standardising text for uniform comparison or storage.
- string\match() - Matches a string against a specified pattern using regular expressions, ideal for extracting or validating segments of text.
- string\matchAll() - Identifies all occurrences of a pattern within a string, enhancing thorough pattern searches.
- string\pad() - Pads a string to a desired length by adding characters to the start or end, useful for formatting text.
- string\pos() - Locates the position of a substring within a string, facilitating text manipulation tasks like slicing.
- string\replace() - Substitutes parts of a string with alternate text, crucial for data cleaning or updates.
- string\split() - Splits a string into an array of substrings based on a delimiter, useful for dissecting structured text.
- string\substring() - Extracts a segment from a string, allowing for focused text manipulation.
- string\test() - Checks if a string fits a regular expression, aiding in validations and checks.
- string\trim() - Removes excess whitespace from the ends of a string, typically used to clean up user entries.
- string\upperCase() - Transforms all characters in a string to uppercase, useful for formatting and displaying text consistently.
These string functions are fundamental for handling and manipulating text within Mythradon formulas, providing system administrators and developers with powerful tools for data management.
string\concatenate( )¶
The string\concatenate() function combines two or more strings into a single string value and returns the result.
Examples:
$someVariable = string\concatenate('ab', 'cd'); // Returns 'abcd'
$someVariable = string\concatenate('ab', 'cd', 'ef'); // Returns 'abcdef'
string\contains( )¶
The string\contains() function evaluates whether STRING contains NEEDLE and returns a boolean value accordingly.
Example:
string\length( )¶
The string\length() function provides the length of a string as an integer value.
Example:
$strLength = string\length('hello world');
output\print($strLength); // will output `11`
string\lowerCase( )¶
The string\lowerCase() function converts all alphabetical characters in STRING to lowercase.
Example:
$value = string\lowerCase('HELLO world');
output\print($value); // will output `hello world`
string\match( )¶
The string\match() function retrieves the first result of matching a STRING using a REGULAR_EXPRESSION. Returns NULL if no matches are found.
Example:
$result = string\match('{token1} foo {token2} bar', '/{[^}]*}/');
output\print($result); // Will output `{token1}`.
Note
The slash character / defines the start and the end of a REGULAR_EXPRESSION.
string\matchAll( )¶
The string\matchAll() Retrieves all results of matching a STRING against a REGULAR_EXPRESSION. Returns NULL if no matches are found.
Example:
// returns an array of strings containing each token ['{token1}', '{token2}']
$tokens = string\matchAll('{token1} foo {token2} bar', '/{[^}]*}/');
$found = array\includes($tokens, '{token2}');
output\print($found); // Returns true
Note
The slash character / defines the start and the end of a REGULAR_EXPRESSION.
string\pad( )¶
The string\pad() function extends STRING to a specified LENGTH using PAD_STRING.
By default, PAD_STRING is a whitespace string ' '.
PAD_TYPE can be 'right', 'left', 'both', with a default of 'right'.
Example:
string\pos( )¶
The string\pos() function retrieves the position of the NEEDLE within the STRING, returning an integer representing the position if found, or false if not found.
Example:
string\replace( )¶
The string\replace() function substitutes all instances of SEARCH with REPLACE in the provided STRING.
Example:
string\replace('Hello {test}', '{test}', 'world'); // will return 'Hello world'.
string\split( )¶
The string\split() function accepts a STRING and a SEPARATOR as arguments and divides the STRING into an array of strings using the SEPARATOR as the delimiter.
Example:
string\substring( )¶
The string\substring() function extracts characters from a STRING starting from a specified START position and extending to a specified LENGTH.
If LENGTH is not provided, the substring starting from START until the end of the STRING will be returned.
If LENGTH is negative, it indicates the number of characters to omit from the end of the STRING.
Examples:
$someVariable = string\substring('abcde', 1, 2); // will return 'bc'
$someVariable = string\substring('abcde', 1, -1); // will return 'bcd'
string\test( )¶
The string\test() function utilises a regular expression (REGULAR_EXPRESSION) to search within the STRING value. It returns TRUE if a match is found and FALSE if no match is found.
Example:
Note
The slash character / defines the start and the end of a REGULAR_EXPRESSION. The /i at the end of the regular express performs a non case sensitive match/search. Without the /i the match/search will be case sensitive and the example would return false.
string\trim( )¶
The string\trim() function strips whitespace (spaces, tabs, and newlines) from both the beginning and end of a string.
It's worth noting that trim() does not modify the original string; rather, it returns a new string with leading and trailing whitespace removed. If you want to modify the original string, you would need to assign the result of trim() back to the original variable.
Example:
string\trim(' hello world ') // will return 'hello world', removing both the leading and trailing spaces.
string\upperCase( )¶
The string\upperCase() function converts alphabetical characters in a string to upper case.
Example:
See also¶
- Array Functions
- Datetime Functions
- Entity Functions
- Env Functions
- Ext Functions
- JSON Functions
- Language Functions
- Number Functions
- Object Functions
- Output Functions
- Password Functions
- Record Functions
- String Functions
- Mythradon Marketing
- Mythradon Sales
- Mythradon Service
- Mythradon System Administration
- Mythradon Tools