0

我有一个标签,我必须在其中放置从数据库中提取的中文字符串,但没有任何结果。我注意到字符串没有从数据库中提取,而所有其他工作正常。我能做些什么?

  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

提前致谢

4

2 回答 2

1

尝试CFStringConvertEncodingToNSStringEncodingkCFStringEncodingBig5_E

另见苹果文档国际 或创建自己的编码这个

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];
于 2012-12-05T11:57:34.760 回答
1

从 sqlite 检索数据时,不要指定编码模式,而是使用以下命令:

NSString *myChineseText = [NSString stringWithFormat:@"%s",(const char*)sqlite3_column_text(statement, index)];

NSLog(@"%@",myChineseText);

希望,它会解决你的问题。:)

于 2012-12-05T12:40:16.163 回答