German characters are not displayed correctly

I am having a problem with character mapping:

Ex: My word is: ÜniversĂ€l but it is displayed as: √Ășnivers√§l when I type this word.

How can I solve this problem?

As shown here, it displays the correct word in the tooltip: It display proper word in hint but when I print the string str1, its print is √Ășnivers√§l

+4
source share
3 answers

Problems with metal umlauts ?

It depends on the encoding of the output channel used.

For instance:

  NSString *universal = @"ÜniversĂ€l"; NSLog(@"Üniversal: %@", universal); printf("%s\n", [universal cStringUsingEncoding:NSMacOSRomanStringEncoding]); printf("%s\n", [universal cStringUsingEncoding:NSISOLatin1StringEncoding]); printf("%s\n", [universal cStringUsingEncoding:NSUTF8StringEncoding]); 

"prints" a string on the terminal in three different encodings. Do any of them suit you?

+2
source

I would try changing the encoding to something more UTF8-ish

 NSString *otherString = [[NSString alloc] initWithCString:"ÜniversĂ€l" encoding:NSMacOSRomanStringEncoding]; NSLog(@"%@",otherString); // outputs √Ășnivers√§l NSString *string = [[NSString alloc] initWithCString:"ÜniversĂ€l" encoding:NSUTF8StringEncoding]; NSLog(@"%@",string); // outputs ÜniversĂ€l 
+1
source

This is not an answer, but I wanted to add a screenshot to my comment.

I dragged UILabel onto my storyboard and tied it to label1. Everything looks good to me. I am using Xcode 4.6 with iOS 6. Tell me if I missed something?

 @interface v1ViewController : UIViewController @property (nonatomic, retain) IBOutlet UILabel *label1; @end @implementation v1ViewController @synthesize label1; - (void)viewDidLoad { [super viewDidLoad]; NSArray *tempArray = [[NSArray alloc] initWithObjects:@"ÜniversĂ€l", nil]; NSString *str2 = [tempArray objectAtIndex:0]; //NSLog(@"str2: %s",[str2 UTF8String]); // outputs √Ășnivers√§l NSLog(@"str2: %@",str2); // outputs ÜniversĂ€l label1.text = str2; } 

enter image description here

0
source

Source: https://habr.com/ru/post/1500152/


All Articles