gpt4 book ai didi

android - 如何将搜索中的引号转义到 ContentProvider?

转载 作者:行者123 更新时间:2023-11-30 03:45:40 26 4
gpt4 key购买 nike

如何将搜索中的引号转义到 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 ");

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

最佳答案

关于

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 ");

关于android - 如何将搜索中的引号转义到 ContentProvider?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15049934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com