Android系统。 SQLite的。删除所有非数字

时间:2014-01-31 09:18:20

标签: android sqlite 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);

但是当我通过子地址8888888搜索DB编号格式+7(888)888-88-88时,光标不会移动到下一个

怎么了?

1 个答案:

答案 0 :(得分:4)

replace中没有正则表达式支持,Android sqlite也不提供regex函数的实现。

您最好的选择是添加另一个用于搜索的列,以及删除无关紧要字符的值。您可以在Java代码中使用正则表达式。

如果这不是一个选项且特殊字符集很小,您可以使用嵌套替换:

replace(replace(replace(replace(address, '+', ''), '-', ''), '(', ''), ')', '')

但是你可以看到这很麻烦。

相关问题