Declarative Objectivity (DO) Language : Operator Expressions : String Operators
String Operators
String operators and regular expression operators provide standard capabilities for working with strings.
Operator
Description
Usage
First Operand
(op1)
Second Operand
(op2)
Third Operand
(op3)
Result Type1
See Also
+
Concatenates two strings
op1 + op2
String
String
String
CONTAINS
Finds a substring
CONTAINS(op1, op2)
op1 CONTAINS op2
String
String
Boolean
SUBSTRING
SUBSTR
Extracts substring
SUBSTRING(op1, op2, op3)
SUBSTRING(op1, op2)
String
Integer
Integer
String
UPPER
Converts to uppercase
UPPER(op1)
String
String
LOWER
Converts to lowercase
LOWER(op1)
String
String
=~
Matches, case sensitive
op1 =~ op2
String
Boolean
!~
Does not match, case sensitive
op1 !~ op2
=~~
Matches, case insensitive
op1 =~~ op2
!~~
Does not match, case insensitive
op1 !~~ op2
1. The string operators return null if either operand is a null value.
Quick Look 
Find the “Luxury” vehicle category, regardless of the casing of the stored string:
FROM VehicleCategory WHERE UPPER(name) == 'LUXURY' RETURN rate;
Concatenate the first and last name of each customer into a single string:
FROM Customers RETURN firstName+' '+lastName;
Return all customers whose last names begin with the letters 'Gr':
FROM Customers WHERE SUBSTRING(lastName, 0, 2) == 'Gr' RETURN *;
Use a regular expression to return all customers whose last names begin with the letters 'Gr':
FROM Customers WHERE lastName =~ '^Gr' RETURN *;
Use a regular expression to return all customers whose last names begin with 'Gr'or 'gr':
FROM Customers WHERE lastName =~~ '^Gr' RETURN *;
Discussion 
For general information about operator formats, operands, and precedence, see About Operator Expressions.
For details about strings, see String Tokens.
Finding Substrings
The CONTAINS operator returns true if the value of the first operand contains the string literal specified with the second operand.
Example. The following statement returns a RentalCompany with a name such as "Acme Auto", which contains the substring 'cm':
FROM RentalCompany WHERE CONTAINS(name, 'cm') RETURN *;
Note:You can perform an equivalent operation using a regular expression operator; see Matching String Patterns.
Extracting Substrings
The SUBSTRING operator extracts a substring that starts at the specified index position and has the specified length. If length is not specified, the rest of the string is extracted.
Examples. The following expression extracts a substring from a name attribute, starting at position zero with a length of four characters:
SUBSTRING(name, 0, 4)
The following statement returns the first four letters of the name of each RentalCompany object:
FROM RentalCompany RETURN SUBSTRING(name, 0, 4);
The following statement returns a RentalCompany with a name with a name such as "Acme Auto", which starts with the four letters 'Acme':
FROM RentalCompany WHERE SUBSTRING(name, 0, 4) == 'Acme' RETURN *;
Note:You can perform an equivalent operation using a regular expression operator; see Matching String Patterns.
Converting Case
The UPPER and LOWER operators convert a string’s characters to all uppercase letters (such as 'ABC') or all lowercase letters (such as 'abc'). These operators are applicable only for characters that represent ASCII alphabet letters, including UTF encodings that represent ASCII characters.
Example. When qualifying a RentalCompany object, the expression in the WHERE clause qualifies the name regardless of the casing of the letters stored in the name attribute.
FROM RentalCompany WHERE UPPER(name) == 'ACME AUTO' RETURN *;
Note:When using these operators on UTF strings, every encoding must represent an ASCII character.
Matching String Patterns
Regular expression operators produce Boolean values based on comparing a string expression to a regular-expression pattern. The left operand is the string expression and the right operand is a string literal containing the pattern. The operators can test whether or not the string matches the pattern, and may take casing differences into account (case-sensitive) or ignore them (case-insensitive).
You can use regular expressions to specify a wide variety of patterns; see Regular Expressions.
The following examples show how to use regular expressions to perform operations equivalent to CONTAINS and SUBSTRING.
Example. When qualifying a RentalCompany object with a name such as "Acme Auto", the expression in the WHERE clause evaluates to true because the name contains the substring 'cm':
FROM RentalCompany WHERE name =~ 'cm' RETURN *;
Example. When qualifying a RentalCompany object with a name such as "Acme Auto", the expression in the WHERE clause evaluates to true because the name starts with the specified letters:
FROM RentalCompany WHERE name =~ '^Acme' RETURN *;