iOS:UTF8解码NSString的问题

时间:2014-02-19 15:27:58

标签: ios sqlite utf-8 character-encoding

当我的查询包含'á', 'é', 'ñ' ...

等字符时,我的代码中存在错误

我必须将NSString解析为“c string”,并将"ñ"等字符解码为"\xc3\xb1"

我的代码:

 NSString *querySchoolClass = [NSString stringWithFormat: @"Select id FROM country where name like 'España';"];
 const char *queryEncoding = [querySchoolClass cStringUsingEncoding: NSUTF8StringEncoding];

我的查询"Select id FROM country where name like 'Espa\xc3\xb1a';"没有结果,因为该表包含"España"。我正在使用带有UTF-8的SQLite。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

你可以这样使用stringWithUTF8String

NSString *querySchoolClass = [NSString stringWithUTF8String:@"Select id FROM country where name like 'Espa\xc3\xb1a';"];
相关问题