SUBSTR
Extracts a substring from a string.
This function corresponds to the substr(X, Y, Z) function in SQLite. It returns a substring of the input string from the column, starting at a specified position, with an optional length.
The
startindex is 1-based. A positive value indicates the starting position from the beginning of the string.A negative
startvalue indicates the starting position from the end of the string. For example, -1 is the last character, -2 is the second to last, and so on.If
lengthis provided, it specifies the number of characters to extract. A negative length is not meaningful and may produce undefined results.If
lengthis omitted, all characters from thestartposition to the end of the string are returned.
This function is an alias for SUBSTRING.
Example
// SELECT substr('KQLite is fun', 1, 6) -> 'KQLite'
select(SUBSTR(StringLiteral("KQLite is fun"), 1, 6))
// Get the last 3 characters
// SELECT substr('KQLite is fun', -3) -> 'fun'
select(SUBSTR(StringLiteral("KQLite is fun"), -3))
// Using a column to get a prefix
val userPrefix = select(SUBSTR(Users.username, 1, 3)).from(Users)Return
A KQLiteColumn of type String containing the extracted substring.
Author
MOHAMMAD AZIM ANSARI
Parameters
The source column or string value from which to extract the substring.
The 1-based starting position for the substring. Negative values count from the end.
The optional number of characters to extract. If omitted, extracts all characters to the end of the string.