NSString声明(NSString declaration)

编程入门 行业动态 更新时间:2024-10-20 11:54:32
NSString声明(NSString declaration)

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

更多推荐

本文发布于:2023-07-05 06:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声明   NSString   declaration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!