我在我的应用程序中使用SQLite数据库,我需要从表中获取数据(UTF8 Cyrilic)。 我尝试了两种方法
NSString *aName = [NSString stringWithFormat:@"%s",(char *)sqlite3_column_text(compiledStatement, 1)];和
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];这个。 第一个从表中获取数据但编码错误。 第二个没有给我任何结果和控制台节目
***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'***?> [NSString stringWithUTF8String:]:NULL cString'
我应该在哪里搜索问题以及如何正确编码?
I'm using SQLite database in my application and i need to get data from table (UTF8 Cyrilic). I've tried 2 methods this
NSString *aName = [NSString stringWithFormat:@"%s",(char *)sqlite3_column_text(compiledStatement, 1)];and
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];this. The first one gets data from the table but with wrong encoding. The second one doesn't give me any result and console shows
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** ?> [NSString stringWithUTF8String:]: NULL cString'
Where I should search problem and how to work right with encodings?
最满意答案
尝试
const char* str = (const char*)sqlite3_column_text(compiledStatement, 1)] NSString* string = [NSString stringWithCString:str encoding:NSUTF8StringEncoding];并确保您使用相同的方法存储日期:
const char* str = [string cStringUsingEncoding:NSUTF8StringEncoding];Try
const char* str = (const char*)sqlite3_column_text(compiledStatement, 1)] NSString* string = [NSString stringWithCString:str encoding:NSUTF8StringEncoding];And sure that you store date by the same method:
const char* str = [string cStringUsingEncoding:NSUTF8StringEncoding];更多推荐
发布评论