You can find more info about the particular regex syntax used in the *_regex methods on this link.
.to_uppercase()
Return the same string in all uppercase characters.
string.to_uppercase() => String// exampledo val ="Where is Brian?"doval.to_uppercase() // "WHERE IS BRIAN?"
.to_lowercase()
Return the same string in all lowercase characters.
string.to_lowercase() => String// exampledo val ="Where is Brian?"doval.to_lowercase() // "where is brian?"
.capitalize()
Return the same string with the first letter in uppercase. The rest of the string remains unchanged.
string.capitalize() => String// exampledo val ="my name is John"doval.capitalize() // "My name is John"
.trim(), .trim_left(), .trim_right()
Returns a new string with both leading and trailing whitespace removed. .trim_left() and .trim_right() only trim the leading and trainling whitespace respectively.
do text =" Where is Brian? "do new_text =text.trim()say new_text // "Where is Brian?"do new_text =text.trim_left()say new_text // "Where is Brian? "do new_text =text.trim_right()say new_text // " Where is Brian?"
.length()
Return the length of the target string.
string.length() => Integer// exampledo val ="Where is Brian?"doval.length() // 15
.contains(String), .contains_regex(String)
Return whether the string contains another string or expression.
haystack.contains(needle) => Booleanhaystack.contains_regex(needle) => Boolean// exampledo val ="Where is Brian?"// does it contain any "r"?doval.contains("r") // true// does it contain the word "where"?doval.contains("where") // false => no, because it is case sensitive// does it contain any number?doval.contains_regex("[0-9]") // true
.replace(), .replace_all(), .replace_regex()
Replace the first, all or any occurrence matching the predicate:
say "toto".replace("o","a") // "tato" the first o char is replacedsay "toto".replace_all("o","a") // "tata" all o chars are replacedsay "toto".replace_regex("[to]","a") // "aaaa" all chars that are t or o are replaced
.starts_with(String), .starts_with_regex(String)
Return whether a string starts with another string or expression.
haystack.starts_with(needle) => Booleanhaystack.starts_with_regex(needle) => Boolean// exampledo val ="Where is Brian?"// does it start with "r"?doval.starts_with("r") // false// does it start with any uppercase letter?doval.starts_with_regex("[A-Z]") // true
.ends_with(String), .ends_with_regex(String)
Return whether a string ends with another string or expression.
haystack.ends_with(needle) => Booleanhaystack.ends_with_regex(needle) => Boolean// exampledo val ="Where is Brian?"// does it end with "r"?doval.ends_with("r") // false// does it end with any uppercase letter?doval.ends_with_regex("[A-Z]") // false
.match(String), .match_regex(String)
Return all the matches of the string or expression in the target string, or Null if none are found.
haystack.match(needle) =>Array[String]haystack.match_regex(needle) =>Array[String]// exampledo val ="Where is Brian?"// does it match with "r"?doval.match("r") // ["r", "r"] => yes, twice!// does it match with any uppercase letter?doval.match_regex("[A-Z]") // ["W", "B"] => yes, and these are the letters!
About _regex methods:
The \ (backslash) character has a special meaning. For technical reasons, in all strings, it must be properly escaped, by convention by adding another \ in front of itself, to avoid being interpreted as a special character. For example, if you mean to write the exact string "\n" you must in fact write \\n, otherwise \n will be interpreted as a line break.
We follow this nomenclature for CSML Regex handling, so a single Regex backslash must be written as a "\\" string, and an escaped backslash (that behaves as a literal "\" string character) must in fact be escaped twice, once for being in a string, and once for being in a Regex: you have to write "\\\\" to result in the Regex syntax \\which in turn matches the literal "\" string.
In a future release of CSML we might introduce a "raw string" method to bypass this limitation.
.is_number(), .is_int(), .is_float()
Return whether the given string represents a numerical value, an int, a float.
string.is_number() => Boolean// exampledo val ="Where is Brian?"doval.is_number() // falsedo val ="42"doval.is_number() // truedoval.is_int() // truedoval.is_float() // false
.split(String)
Split a string by a given separator and return an array containing all elements in order. The separator can be a single or multiple characters. If the separator can not be found in the string, the returned array will only contain the original string.
string.split(String) =>Array[String]// exampledo val ="this is a long string"doval.split(" ") // ["this", "is", "a", "long", "string"]doval.split("is") // ["th", " ", " a long string"]doval.split("camembert") // ["this is a long string"]
.slice(start, end) => String
Cut a string between the start and end characters. Some rules apply:
If end is not specified, all the characters after start are returned.
When specified, end must be ≥ start.
If any of the parameters is < 0, the count is made from the end of the string.
say "https://mozilla.org/?x=шеллы".encode_uri()say "https://mozilla.org/?x=шеллы".encode_uri_component()say "https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B".decode_uri()say "https%3A%2F%2Fmozilla.org%2F%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B".decode_uri_component()