OGeek|极客世界-中国程序员成长平台

标题: ios - 在 SQLite 中处理编码的困难 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 13:35
标题: ios - 在 SQLite 中处理编码的困难

我正在尝试从 SQLite 文件中获取信息,当我运行查询时,信息以 ASCII 编码返回。我正在使用下面的代码将返回的信息放入一个字符串中。

[NSString stringWithCStringchar *)sqlite3_column_text(compiledStatement, 2) encoding:NSASCIIStringEncoding];

当我尝试使用 UTF8 编码将返回的信息放入字符串时,它不起作用。以下代码用于当前商店的应用程序中。

[NSString stringWithUTF8Stringchar *)sqlite3_column_text(compiledStatement, 2)];

字符串为空。如何转换 SQLite 文件以使其使用 UTF8 编码?商店的当前版本的应用程序使用上面的后一个代码,所以我需要弄清楚如何转换文件,而不是更改应用程序中的代码。



Best Answer-推荐答案


您可以将 const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);stringWithCharacters:length: 一起使用(UTF16)

const unichar *text = sqlite3_column_text16(_sqlite_stmt, columnIndex);
if (text) {
   NSUInteger length = sqlite3_column_bytes16(_sqlite_stmt, columnIndex)/sizeof(unichar);
   article = [NSString stringWithCharacters:text length:length];
}

关于ios - 在 SQLite 中处理编码的困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18211860/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4