1

如何将搜索中的引号转义到 ContentProvider?像这样查询:

String value = "O'Key" ;/ / string contains a quote

Cursor people = cr.query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String [] {Phone.DISPLAY_NAME, Phone.NUMBER}, Phone.DISPLAY_NAME + "= '" + value + "'", null, Phone.DISPLAY_NAME + "ASC ");

这样的请求会产生错误,因为字符串中的引号被解释为行尾。需要转义字符,但是\'-在这里不起作用!抱歉英语不好。预先感谢您的帮助。

4

1 回答 1

1

关于什么

String value = "O'Key" ;/ / string contains a quote

Cursor people = cr.query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
    new String [] {Phone.DISPLAY_NAME, Phone.NUMBER},
    Phone.DISPLAY_NAME + "=?",
    new String[] {value},
    Phone.DISPLAY_NAME + "ASC ");
于 2013-02-24T08:25:59.023 回答