This site has been deprecated. Do not edit pages here. Please visit the new Pico Labs documentation.


Skip to end of metadata
Go to start of metadata

The following operators are valid for strings.

capitalize()

The capitalize() operator capitalizes the first character in the target string. 

decode()

The decode() operator converts a JSON string into the equivalent KRL data structure. For example:

Note that if the content in the target is not valid JSON, decode() returns the string unchanged without warning. JSON Lint is your friend. 

If target is a string, a map structure will be returned with "error" as the key with the original string in an array as the value. example { "error" : [ "string" ] } .

extract()

The extract() operator matches the string using a regular expression given as the sole argument and returns the specified capture groups as an array. For example:

Note that if the regular expression does not contain at least one capture group, the resulting array will be empty.

lc()

The lc() operator returns the lowercase version of the original string. For example:

match()

The match() operator takes a regular expression as its argument. The result is true if the regular expression matches the string and false otherwise. For example:

ord()

The ord() operator returns a numeric ASCII value of the first character in the string on which it operates.  For example:

The inverse of ord() is chr().

replace()

The replace() operator takes two arguments: a regular expression and a string. The returned string is the original string with any match of the regular expression replaced by the second argument. You can use any captured values in the second, substitute string by naming them with $1, $2, and so on. The first captured value will be substituted for $1, the second for $2, and so on. For example:

In the final example, I was careful to ensure that the regular expression matched the entire URL, so that the substitution of $1 resulted in just the domain name. This same result could be more easily achieved using extract()—although the result, e, would be an array:

split()

The split() operator takes a regular expression as its sole argument. The regular expression is used to split the original string into an array. For example:

sprintf()

The sprintf() operator can be applied to either a number or a string. The operator takes a formatting string as its sole argument. The formatting string follows the conventions for sprintf() established in other languages. Specifically, the KRL version of sprintf() follows the formatting conventions for Perl. For example:

substr()

The substr() operator returns a substring of the target string. The operator takes an argument that gives an offset from the start of the string to begin returning the substring and an optional length that gives the desired length of the substring. If the length is omitted, the substring to the end of the original string from the offset will be returned. If the length is negative, the length will be caluclated from the end of the string. For example:

uc()

The uc() operator returns the uppercase version of the original string. For example: