NSString 声明

发布于 2024-12-18 05:17:26 字数 557 浏览 1 评论 0原文

我在我的应用程序中使用 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动次打次papapa 2024-12-25 05:17:26

尝试

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文