- Reference >
- Operators >
- Aggregation Pipeline Operators >
- String Aggregation Operators >
- $substr (aggregation)
$substr (aggregation)¶
On this page
Definition¶
-
$substr
¶ Returns a substring of a string, starting at a specified index position and including the specified number of characters. The index is zero-based.
$substr
has the following syntax:The arguments can be any valid expression as long as long as the first argument resolves to a string, and the second and third arguments resolve to integers. For more information on expressions, see Expressions.
Behavior¶
If <start>
is a negative number, $substr
returns an
empty string ""
.
If <length>
is a negative number, $substr
returns a
substring that starts at the specified index and includes the rest of
the string.
$substr
is not encoding aware and if used improperly may
produce a result string containing an invalid UTF-8 character sequence.
$substr
only has a well-defined behavior for strings of ASCII characters.