开发者

Special Characters from SQLite DB

开发者 https://www.devze.com 2022-12-28 18:50 出处:网络
I read from a sqlite db to my i开发者_Go百科phone app. Within the texts sometimes there are special characters like \'xf2\' or \'xe0\' as I can see in the debugger in the char* data type. When I try t

I read from a sqlite db to my i开发者_Go百科phone app. Within the texts sometimes there are special characters like 'xf2' or 'xe0' as I can see in the debugger in the char* data type. When I try to transform the chars to an NSString Object by using initWithUTF8String, I get a nil back.

How can I transform such special characters?


It looks like encoding issue. You can get 'xf2' or 'xe0' when you have such symbols as © or ®. Those symbols need 2 bytes, and sqlite can interpret each byte of symbol as separate symbol.
So, try to use not initWithUTF8String, but initWithCString:

NSString *stringFromDB = [[NSString alloc] initWithCString:charsArrayFromDB 
                                                  encoding:NSASCIIStringEncoding];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号