0

如果字符串是,如何转义单引号和双引号

t"'e'"s""t''

换句话说,如何转义包含单引号和双引号的字符串中的引号。

这个例子是这样的:

    String whereClauseToTracks = MediaStore.Audio.Media.ARTIST + " = '" + artist + "' "; // t"'e'"s""t'' - instead of artist
    Cursor cursorToTracks = mResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI , new String[] { MediaStore.Audio.Media.ALBUM }, whereClauseToTracks, null, null);

当字符串包含引号时,我得到 sql lite 异常。

4

2 回答 2

1

像这样使用selectionArgs和: ?selection

String selection= MediaStore.Audio.Media.ARTIST + " = ?";
Cursor cursorToTracks = mResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI , new String[] { MediaStore.Audio.Media.ALBUM }, selection, new String[] {artist}, null);
于 2012-04-20T11:02:56.790 回答
0

采用 \' \”

String whereClauseToTracks = MediaStore.Audio.Media.ARTIST + " = '" + "t\"\'e\'\"s\"\"t\'\'" + "' ";    
于 2012-04-20T10:52:35.213 回答