Name

substr() — Extract a substring

Common Usage

substr( string, index, count )
substr( string, index )

Description

The substr() function extracts and returns a substring from string . The position of the substring is determined by index and its length is determined by count .

If any parameter is NULL, a NULL will be returned. Otherwise, if string is not a BLOB it will be assumed to be a text value. The index and count parameters will be interpreted as integers. If count is not given, it will effectively be set to an infinitely large positive value.

If index is positive, it is used to index characters from the beginning of string . The first character has an index of 1. If index is negative, it is used to index characters from the end of string . In that case, the last character has an index of ‒1. An index of 0 will result in undefined behavior.

If count is positive, then count number of characters, starting with the indexed character, will be included in the returned substring. If count is negative, the returned substring will consist of count number of characters, ending with the indexed character. The returned substring may be shorter than count if the indexed position is too close to the beginning or end of string . A count of zero will result in an empty string.

This function can also be used on BLOB values. If string is a BLOB, both the index and count values will refer to bytes, rather than characters, and the returned value will be a BLOB, ...

Get Using SQLite now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.