SUBSTRING
Extracts a substring from a string. This is an alias for the SUBSTR function.
This function corresponds to the substring(X, Y, Z) or substr(X, Y, Z) function in SQLite. It returns a substring of the input string from the column. The portion of the string is defined by the start position and the 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.If
lengthis provided, it specifies the number of characters to extract.If
lengthis omitted, all characters from thestartposition to the end of the string are returned.
Example
// SELECT substring('KQLite is fun', 1, 6) -> 'KQLite'
select(SUBSTRING(StringLiteral("KQLite is fun"), 1, 6))
// Get the last 3 characters
// SELECT substring('KQLite is fun', -3) -> 'fun'
select(SUBSTRING(StringLiteral("KQLite is fun"), -3))
// Using a column
val userInitials = select(SUBSTRING(Users.firstName, 1, 1)).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.