String Functions
A set of functions that help you manipulate string variables
clean
Creates a valid variable name from the input string - spaces converted to underscores and invalid characters removed.
Syntax
string = clean(varname)
The following characters are removed from the input string:
(){}!/"£$%^&*\[]
Example
vn = clean("name full of [chars like this[] and that()!")
print vn
NAME_FULL_OF_CHARS_LIKE_THIS_AND_THAT
compare
Compares the contents of 2 non-null strings, returns true if they are the same
Syntax
boolean = compare(str1, str2)
Example
print compare("Hello", "hello")
false
```js
print compare("Hello", "Hello")
true
concatenate
Joins 2 non-null strings together
Syntax
string = concatenate(str1, str2)
Example
str = concatenate("Cares", "s")
print str
Caress
contains
Returns true if a string contains another string
Syntax
boolean = contains(str1, str2)
Example
print contains("one,two,three,four,five", "two")
true
endsWith
Tests to see if the first string ends with the specified suffix. If either the string or the suffix are null, it returns false
Syntax
boolean = endsWith(str, suffix)
Example
print endsWith("Patent", "tent")
> true
equals
Checks to see if 2 strings are the same
Syntax
boolean equals(str1, str2)
Example
print equals("Hello", "hello")
print equals("Hello", "Hello")
false
true
json
Converts the input variable of any type to a JSON formatted string
Syntax
string = json(var)
Example
obj = Object()
obj.name = "John"
obj.age = 43
print json(obj)
Displays
> {
"_id": "obj",
"age": "43",
"name": "John"
}
left
Creates a new string from the 'amount' leftmost characters of another string
Syntax
string = left(string, amount)
Example
print left("The end is nigh", 7)
The end
length
Returns the length of a string
Syntax
int = length(string)
Example
print length("The end is nigh")
15
lower
Returns a copy of the passed in string with all the characters converted to lower case
Syntax
stringlower = lower(string)
Example
print lower("Who WhAT WhY")
who what why
remove
Removes all the characters according to the regex parameter from the passed in string
Syntax
string = remove(string, regex)
Example
print remove("The end is nigh", "e")
Th nd is nigh
```js
print remove("The end is nigh", "\[ei\]")
Th nd s ngh
replace
Replaces each substring of the input string that matches the literal match string with the specified literal replacement string
Syntax
string = replace(string, match, replacement)
Example
print replace("The end is nigh", "end", "start")
The start is nigh
startsWith
Tests to see if the first string starts with the specified prefix. If either the string or the prefix are null, it returns false
Syntax
boolean = startsWith(str, prefix)
Example
print startsWith("Patent", "Pat")
true
trim
Returns a string with any space characters from the start or end of the string removed
Syntax
string = trim(string)
Example
print trim(" This String ")
This String
```js
print "[" + trim(" This String ") + "]"
[This String]
upper
Returns a copy of the passed in string with all the characters converted to UPPER case
Syntax
stringlower = upper(string)
Example
print lower("Who WhAT WhY")
WHO WHAT WHY