rules. String
Primitive type representing a string value.
Strings can be lexicographically compared using the ==
, !=
, >
,
<
, >=
and <=
operators.
Strings can be concatenated using the +
operator:
// Concatenate a username and an email domain 'username' + '@domain.com'
Sub-strings can be accessed using the index operator []
and the range operator [i:j]
.
// Check if the first character of a string is 'a' mystring[0] == 'a' // Check if the string starts with 'abc' mystring[0:2] == 'abc'
Boolean, integer, float, and null values can be converted into strings using the string()
function:
string(true) == "true" string(1) == "1" string(2.0) == "2.0" string(null) == "null"
Methods
lower
lower() returns rules.String
Returns a lowercase version of the input string.
- Returns
-
non-null rules.String
the lowercase string.
Example
'ABC'.lower() == 'abc'
'ABC123'.lower() == 'abc123'
matches
matches(re) returns rules.Boolean
Performs a regular expression match on the whole string.
Parameter |
|
---|---|
re |
A regular expression using Google RE2 syntax. Value must not be null. |
- Returns
-
non-null rules.Boolean
true if the whole string matches, false otherwise.
Example
'user@domain.com'.matches('.*@domain[.]com') == true
'banana'.matches('.*@domain[.]com') == false
size
size() returns rules.Integer
Returns the number of characters in the string.
- Returns
-
non-null rules.Integer
the number of characters.
Example
'a'.size() == 1
'abc'.size() == 3
split
split(re) returns rules.List
Splits a string according to a regular expression.
Parameter |
|
---|---|
re |
A regular expression using Google RE2 syntax. Value must not be null. |
- Returns
-
non-null rules.List
a list of strings.
Example
'a/b/c'.split('/') == ['a', 'b', 'c']
trim
trim() returns rules.String
Returns a version of the string with leading and trailing spaces removed.
- Returns
-
non-null rules.String
the trimmed string.
Example
' a '.trim() == 'a'
'b'.trim() == 'b'
upper
upper() returns rules.String
Returns an uppercase version of the input string.
- Returns
-
non-null rules.String
the uppercase string.
Example
'abc'.upper() == 'ABC'
'abc123'.upper() == 'ABC123'