class string
This is the built-in string class.
In general, a JewelScript string is an immutable object, meaning once created, it's state can't be altered. There is one exception to that rule: Operator += will actually modify the string object left from the operator. JewelScript strings are limited to 8-bit ANSI characters. Their length is limited to 2 gigabytes. Zero-bytes in the string are handled gracefully by the runtime. However, they may cause problems when passing strings to other native functions, so they are discouraged.
Global Functions
string ascii (const int) | Returns a string containing the specified ANSI character. |
int charIsControl (const int) | Returns true if the specified character is a control character. |
int charIsDigit (const int) | Returns true if the specified character is a digit. |
int charIsLetter (const int) | Returns true if the specified character is a letter. |
int charIsLetterOrDigit (const int) | Returns true if the specified character is a letter or digit. |
int charIsLowerCase (const int) | Returns true if the specified character is a lower case letter. |
int charIsPunctuation (const int) | Returns true if the specified character is a puctuation character. |
int charIsUpperCase (const int) | Returns true if the specified character is an upper case letter. |
int charIsValidForPath (const int) | Returns true if the specified character is a valid file name / path name character. |
int charIsValidForUrl (const int) | Returns true if the specified character is a valid URL character. |
int charIsWhitespace (const int) | Returns true if the specified character is a white space character. |
int compare (const var, const var) | Compares two strings. |
string fill (const int, const int) | Creates a string filled with the specified amount of the specified character. |
string format (const string, const var) | Creates a formatted string using ANSI format specifiers. |
int isEmpty (const string) | Returns true if the specified string is null or empty. |
string join (const string[], const string) | Concatenates all elements from the given string array into one string. |
Constructors
string () | Constructs a new, empty string. |
string (const int) | Constructs a new string representation of the specified integer number. |
string (const float) | Constructs a new string representation of the specified floating-point number. |
Convertors
int convertor () | Tries to parse this string into an integer number. |
float convertor () | Tries to parse this string into a floating-point number. |
Methods
int charAt (const int) | Returns the character at the specified zero-based index from this string. |
string clone () | Returns a true copy of this string. |
int containsAllOf (const string[]) | Returns true if this string contains all of the keywords in the given array, otherwise false. |
int containsAnyOf (const string[]) | Returns true if this string contains any of the keywords in the given array, otherwise false. |
int containsAt (const int, const string) | Returns true if this string contains the specified substring at the specified index position. |
string decodeUrl (const string) | Decodes all URL entities in the format %hh in this string. |
string encodeUrl (const string) | Encodes all invalid URL characters in this string using %hh entities. |
int endsWith (const string) | Returns true if this string ends with the specified substring. |
int indexOf (const int, const int) | Returns the index of the first occurrence of the specified character in this string. |
int indexOf (const string, const int) | Returns the index of the first occurrence of the specified substring in this string. |
string insert (const int, const int) | Inserts the specified character at the given index position into this string and returns the result as a new string. |
string insert (const string, const int) | Inserts the specified substring at the given index position into this string and returns the result as a new string. |
int lastIndexOf (const int, const int) | Returns the index of the last occurrence of the specified character in this string. |
int lastIndexOf (const string, const int) | Returns the index of the last occurrence of the specified substring in this string. |
stringMatch[] matchArray (const string[]) | Treats this string as a keyword and searches the given array for occurrences of the keyword. |
stringMatch[] matchString (const string[]) | Treats the given array as a list of keywords and searches this string for occurrences of these keywords. |
string process (string::processor, var) | Calls the specified delegate for all characters in this string. |
string remove (const int) | Removes all characters from the given index position to the end of the string. |
string remove (const int, const int) | Removes all characters in the specified range from this string. |
string replace (const int, const int) | Replaces all occurrences of the specified character by the given character. |
string replace (const string, const string) | Replaces all occurrences of the specified search string by the given replace string. |
string replace (const int, const int, const string) | Replaces the specified character range by the replace string. |
string reverse () | Reverses the order of all characters in this string and returns the result as a new string. |
string spanExcluding (const string, const int) | Starting from index, returns all characters, which are NOT included in the specified character set. |
string spanIncluding (const string, const int) | Starting from index, returns all characters, which are included in the specified character set. |
string[] split (const string) | Splits this string into an array of tokens based on the given set of delimiter characters. |
string[] split (const string, const int) | Splits this string into an array of tokens based on the given set of delimiter characters. |
int startsWith (const string) | Returns true if this string starts with the specified substring. |
string subString (const int) | Returns all characters from the given starting index to the end of this string as a substring. |
string subString (const int, const int) | Returns the specified character range from this string as a substring. |
string toLower () | Converts all characters of this string into lower case using the current ANSI locale and returns the result as a new string. |
string toUpper () | Converts all characters of this string into upper case using the current ANSI locale and returns the result as a new string. |
string trim () | Removes all control and white space characters from the beginning and end of this string. |
Properties
int lastChar () | Returns the last character in this string. |
int length () | Returns the length of this string in characters. |
Reference
function string ascii (const int chr) |
Returns a string containing the specified ANSI character. |
function int charIsControl (const int c) |
Returns true if the specified character is a control character. |
function int charIsDigit (const int c) |
Returns true if the specified character is a digit. |
function int charIsLetter (const int c) |
Returns true if the specified character is a letter. |
function int charIsLetterOrDigit (const int c) |
Returns true if the specified character is a letter or digit. |
function int charIsLowerCase (const int c) |
Returns true if the specified character is a lower case letter. |
function int charIsPunctuation (const int c) |
Returns true if the specified character is a puctuation character. |
function int charIsUpperCase (const int c) |
Returns true if the specified character is an upper case letter. |
function int charIsValidForPath (const int c) |
Returns true if the specified character is a valid file name / path name character. |
function int charIsValidForUrl (const int c) |
Returns true if the specified character is a valid URL character. |
function int charIsWhitespace (const int c) |
Returns true if the specified character is a white space character. |
function int compare (const var value1, const var value2) |
Compares two strings. This function can be used as comparator delegate for the list::sort() and array::sort() methods. |
function string fill (const int chr, const int length) |
Creates a string filled with the specified amount of the specified character. |
function string format (const string format, const var v) |
Creates a formatted string using ANSI format specifiers. Multiple arguments may be passed to this function by directly passing an array expression: string str = string::format("%s, %d, %f", {x, y, z}) |
function int isEmpty (const string s) |
Returns true if the specified string is null or empty. |
function string join (const string[] values, const string seperator) |
Concatenates all elements from the given string array into one string. The elements will be seperated by the specified seperator string. |
method string () |
Constructs a new, empty string. |
method string (const int) |
Constructs a new string representation of the specified integer number. |
method string (const float) |
Constructs a new string representation of the specified floating-point number. |
explicit method int convertor () |
Tries to parse this string into an integer number. This conversion requires an explicit type cast to confirm that a conversion is wanted. If parsing the string fails, the result is 0. |
explicit method float convertor () |
Tries to parse this string into a floating-point number. This conversion requires an explicit type cast to confirm that a conversion is wanted. If parsing the string fails, the result is 0. |
method int charAt (const int index) |
Returns the character at the specified zero-based index from this string. If the index is out of range, zero is returned. |
method string clone () |
Returns a true copy of this string. |
method int containsAllOf (const string[] keywords) |
Returns true if this string contains all of the keywords in the given array, otherwise false. If you need to know where the keywords matched the string, use matchString() instead. |
method int containsAnyOf (const string[] keywords) |
Returns true if this string contains any of the keywords in the given array, otherwise false. If you need to know which keyword matched the string and where, use matchString() instead. |
method int containsAt (const int index, const string s) |
Returns true if this string contains the specified substring at the specified index position. |
method string decodeUrl (const string except) |
Decodes all URL entities in the format %hh in this string. The optional character set 'except' can list characters which should NOT be decoded. The result is returned as a new string. |
method string encodeUrl (const string except) |
Encodes all invalid URL characters in this string using %hh entities. The optional character set 'except' can list characters which should NOT be encoded. The result is returned as a new string. |
method int endsWith (const string s) |
Returns true if this string ends with the specified substring. |
method int indexOf (const int chr, const int index) |
Returns the index of the first occurrence of the specified character in this string. The search starts at the given index. If the specified character was not found, -1 is returned. |
method int indexOf (const string s, const int index) |
Returns the index of the first occurrence of the specified substring in this string. The search starts at the given index. If the specified substring was not found, -1 is returned. |
method string insert (const int chr, const int index) |
Inserts the specified character at the given index position into this string and returns the result as a new string. |
method string insert (const string s, const int index) |
Inserts the specified substring at the given index position into this string and returns the result as a new string. |
method int lastIndexOf (const int chr, const int index) |
Returns the index of the last occurrence of the specified character in this string. The search starts at the given index. If the specified character was not found, -1 is returned. |
method int lastIndexOf (const string s, const int index) |
Returns the index of the last occurrence of the specified substring in this string. The search starts at the given index. If the specified substring was not found, -1 is returned. |
method stringMatch[] matchArray (const string[] strings) |
Treats this string as a keyword and searches the given array for occurrences of the keyword. Any matches are returned as an array of stringMatch instances. If no match is found, an array with zero length is returned. |
method stringMatch[] matchString (const string[] keywords) |
Treats the given array as a list of keywords and searches this string for occurrences of these keywords. Any matches are returned as an array of stringMatch instances. If no match is found, an array with zero length is returned. |
method string process (string::processor fn, var args) |
Calls the specified delegate for all characters in this string. The delegate can convert the given character or return zero. All non-zero results of the delegate will be concatenated to a new string that is then returned. |
method string remove (const int index) |
Removes all characters from the given index position to the end of the string. The result is returned as a new string. |
method string remove (const int index, const int length) |
Removes all characters in the specified range from this string. The result is returned as a new string. |
method string replace (const int schr, const int rchr) |
Replaces all occurrences of the specified character by the given character. The result is returned as a new string. |
method string replace (const string search, const string replace) |
Replaces all occurrences of the specified search string by the given replace string. The result is returned as a new string. |
method string replace (const int index, const int length, const string replace) |
Replaces the specified character range by the replace string. The replace string may be longer or shorter than the source range. The result is returned as a new string. |
method string reverse () |
Reverses the order of all characters in this string and returns the result as a new string. |
method string spanExcluding (const string charSet, const int index) |
Starting from index, returns all characters, which are NOT included in the specified character set. The method stops at the first character that is included in the character set. |
method string spanIncluding (const string charSet, const int index) |
Starting from index, returns all characters, which are included in the specified character set. The method stops at the first character that is not included in the character set. |
method string[] split (const string separators) |
Splits this string into an array of tokens based on the given set of delimiter characters. The returned array will contain all text between delimiters, but not the delimiters itself. A delimiter directly following another delimiter will produce an empty string element. If this string does not match any delimiter, the resulting array will contain a single element, which is a copy of this string. |
method string[] split (const string separators, const int discard) |
Splits this string into an array of tokens based on the given set of delimiter characters. The returned array will contain all text between delimiters, but not the delimiters itself. If 'discard' is 'false', a delimiter directly following another delimiter will produce an empty string element in the array. If set to 'true', empty strings will not be added to the array. If this string does not match any delimiter, the resulting array will contain a single element, which is a copy of this string. |
method int startsWith (const string s) |
Returns true if this string starts with the specified substring. |
method string subString (const int index) |
Returns all characters from the given starting index to the end of this string as a substring. |
method string subString (const int index, const int length) |
Returns the specified character range from this string as a substring. |
method string toLower () |
Converts all characters of this string into lower case using the current ANSI locale and returns the result as a new string. |
method string toUpper () |
Converts all characters of this string into upper case using the current ANSI locale and returns the result as a new string. |
method string trim () |
Removes all control and white space characters from the beginning and end of this string. The result is returned as a new string. |
accessor int lastChar () |
Returns the last character in this string. If the string is empty, zero is returned. |
accessor int length () |