我从 SQLite 数据库中检索了很多数据。检索时,我将其映射到应用程序中的不同 View 。我的表中有一个文本字段,我不想从中获取全文,只是前 n 个字符。因此,如果我的查询是:
Select description from articles where id='29';
那么如何从描述中获取子字符串呢?谢谢
最佳答案
使用 substr
函数。
substr(X,Y,Z) substr(X,Y) substring(X,Y,Z) substring(X,Y)
The
substr(X,Y,Z)
function returns a substring of input stringX
that begins with theY-th
character and which isZ
characters long. IfZ
is omitted thensubstr(X,Y)
returns all characters through the end of the stringX
beginning with theY-th
. The left-most character ofX
is number 1. IfY
is negative then the first character of the substring is found by counting from the right rather than the left. IfZ
is negative then theabs(Z)
characters preceding theY-th
character are returned. IfX
is a string then characters indices refer to actual UTF-8 characters. IfX
is a BLOB then the indices refer to bytes.
substring()
is an alias forsubstr()
beginning with SQLite version 3.34.
关于database - 如何在 SQLIte 中获取子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10413055/