在目标c中逃避%

Sau*_*abh 11 objective-c

我想做一个sql语句 -

sqlStatement = [NSString stringWithFormat:@"SELECT * FROM movies where title like '%%@%'",searchKeyword];
Run Code Online (Sandbox Code Playgroud)

但是sqlStatement正在成为 -

"选择*来自电影,其中标题为'%@'"

我想成功

"选择*来自电影,其中标题为'%searchKeyword%'"

如何逃脱"%"字符?

谢谢

Aci*_*ibi 23

试试:

sqlStatement = [NSString stringWithFormat:@"SELECT * FROM movies where title like '%%%@%%'",searchKeyword];
Run Code Online (Sandbox Code Playgroud)

"%%"是打印'%'字符的方式.

  • 我正在等待'小鲍比桌 - 电影'出来. (3认同)