我有一个标签,我必须从数据库中提取一个中文字符串,但没有任何结果。我注意到字符串不是从数据库中提取的,而其他所有字符串都正常工作。我该怎么办?
char *subTitle= (char*)sqlite3_column_text(statement,13);
NSLog(@" The sutitle is %s", subTitle);
//The sutitle is
rowTable.sottotitolo = [[NSString alloc]initWithUTF8String: subTitle];
NSLog(@"The subtitle is %@", rowTable.sottotitolo);
//The subtitle is
使用西方字母以外的方法?
NSLog(@"The string in chinese is %@", self.chinaTable.subtitle);
//The string in chinese is
//is not printed to the screen,but the database is written correctly
self.labelTitle.text = self.chinaTable.subtitle;
//empty out
提前致谢
答案 0 :(得分:1)
尝试CFStringConvertEncodingToNSStringEncoding
和kCFStringEncodingBig5_E
。
另见apple doc和international 或者用于创建自己的编码see 和this
unichar ellipsis = 0x2026;
NSString *theString = [NSString stringWithFormat:@"To be continued%C", ellipsis];
// custom encoding
NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingDOSChineseTrad);
NSData *asciiData = [theString dataUsingEncoding:encoding
allowLossyConversion:YES];
NSString *asciiString = [[NSString alloc] initWithData:asciiData
encoding:encoding];
答案 1 :(得分:1)
从sqlite检索数据时,不要指定编码模式,请使用:
NSString *myChineseText = [NSString stringWithFormat:@"%s",(const char*)sqlite3_column_text(statement, index)];
NSLog(@"%@",myChineseText);
希望,它会解决你的问题。 :)