String methods

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
// example
do val = "Where is Brian?"
do val.to_uppercase() // "WHERE IS BRIAN?"

.to_lowercase()

Return the same string in all lowercase characters.

string.to_lowercase() => String
// example
do val = "Where is Brian?"
do val.to_lowercase() // "where is brian?"

.length()

Return the length of the target string.

string.length() => Integer
// example
do val = "Where is Brian?"
do val.length() // 15

.contains(String), .contains_regex(String)

Return whether the string contains another string or expression.

haystack.contains(needle) => Boolean
haystack.contains_regex(needle) => Boolean
// example
do val = "Where is Brian?"
// does it contain any "r"?
do val.contains("r") // true
// does it contain the word "where"?
do val.contains("where") // false => no, because it is case sensitive
// does it contain any number?
do val.contains_regex("[0-9]") // true

.starts_with(String), .starts_with_regex(String)

Return whether a string starts with another string or expression.

haystack.starts_with(needle) => Boolean
haystack.starts_with_regex(needle) => Boolean
// example
do val = "Where is Brian?"
// does it start with "r"?
do val.starts_with("r") // false
// does it start with any uppercase letter?
do val.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) => Boolean
haystack.ends_with_regex(needle) => Boolean
// example
do val = "Where is Brian?"
// does it end with "r"?
do val.ends_with("r") // false
// does it end with any uppercase letter?
do val.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]
// example
do val = "Where is Brian?"
// does it match with "r"?
do val.match("r") // ["r", "r"] => yes, twice!
// does it match with any uppercase letter?
do val.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.

This Python documentation explains why it especially matters in Regex syntax to escape backslashes: https://docs.python.org/2/howto/regex.html#the-backslash-plague

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
// example
do val = "Where is Brian?"
do val.is_number() // false
do val = "42"
do val.is_number() // true
do val.is_int() // true
do val.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]
// example
do val = "this is a long string"
do val.split(" ") // ["this", "is", "a", "long", "string"]
do val.split("is") // ["th", " ", " a long string"]
do val.split("camembert") // ["this is a long string"]