SQLite MYSQL字符编码 [英] SQLite MYSQL character encoding
本文介绍了SQLite MYSQL字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个奇怪的情况,以下代码可以工作,但是XCode警告它已弃用...
I have a strange situation where the following code works however XCode warns it is deprecated...
NSString *col1 = [NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 0)];
但是,如果我设置了编码,那么这是不赞成使用的方法,则字符串输出错误!我已经尝试了所有编码,但是没有用!
However as that is the deprecated method if I set an encoding the string comes out wrong! I have tried all the encodings but none work!
NSString *col1 = [NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 0) encoding:NSASCIIStringEncoding];
推荐答案
我原本希望讽刺小说的建议能奏效,但这是我使用的可可版本:
I would have expected satire's suggestion to have worked, however here is the Cocoa version of what I use:
如果您要处理utf16
If you are dealing with utf16
int len = sqlite3_column_bytes16(compiledStatement, col) / 2;
unichar *chars = (unichar*)sqlite3_column_text16(compiledStatement, col);
NSString *str = [NSString stringWithCharacters:chars length:len];
如果您使用的是utf8
If you are using utf8
int len = sqlite3_column_bytes(compiledStatement, col);
char *chars = (char*)sqlite3_column_text(compiledStatement, col);
NSString *str = [NSString stringWithUTF8String:chars length:len];
这篇关于SQLite MYSQL字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文