use*_*546 3 sqlite android replace
我想查询没有非数字符号的字段。
Cursor c=context.getContentResolver().query(Uri.parse("content://mms-sms/canonical-addresses/"), new String[] {"address","_id"}, "replace("+"address"+", '[^0-9]','')"+" LIKE ?", new String[] {"%"+subaddress+"%"}, null);
Run Code Online (Sandbox Code Playgroud)
但是当我通过子地址 8888888 在 DB 编号格式 +7(888)888-88-88 中搜索时,光标不会 moveToNext
怎么了?
没有正则表达式支持replace
,Android sqlite 也不提供该regex
函数的实现。
您最好的选择是添加用于搜索的另一列,并且其中的值将去除无关紧要的字符。您可以在 Java 代码中使用正则表达式。
如果这不是一个选项并且特殊字符集很小,则可以使用嵌套替换:
replace(replace(replace(replace(address, '+', ''), '-', ''), '(', ''), ')', '')
Run Code Online (Sandbox Code Playgroud)
但是正如你所看到的,这变得很麻烦。