Ortensia C.
Ortensia C.

Reputation: 4716

Chinese string in the text of a label

I have a label where I have to put a string in Chinese extracted from a database, but nothing comes out. I noticed that the string is not pulled from database, while all other work correctly. What can I do?

  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

Using methods other than Western alphabet?

   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

Thanks in advance

Upvotes: 0

Views: 941

Answers (2)

HDdeveloper
HDdeveloper

Reputation: 4404

Try CFStringConvertEncodingToNSStringEncoding and kCFStringEncodingBig5_E.

Also see apple doc and for international or for creating own encoding see and 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];

Upvotes: 1

Mohit_Jaiswal
Mohit_Jaiswal

Reputation: 840

While you retrieving your data from sqlite, instead of specifying the encoding schema, use this:

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

NSLog(@"%@",myChineseText);

Hope, it'll solved your problem. :)

Upvotes: 1

Related Questions