Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"incomplete universal character name" with stringWithUTF8String

Tags:

when i try to convert form utf-8 string to NSString like so:

NSString *s = [NSString stringWithUTF8String:"\U0627\U0644\U0641\U0631\U0646"]; NSLog(@"%@", s); 

i get the compile error:

incomplete universal character name 

note that it sometime just works fine:

NSString *UAE = [NSString stringWithUTF8String:"\U0627\U0644\U0641\U0631\U0646"];     NSLog(@"%@", UAE); 

and the output:

الامارات 

so why is that happening? please help.

like image 236
Nasser Avatar asked Mar 26 '10 10:03

Nasser


1 Answers

\U and \u are not the same thing. The \U escape expects 8 (hex) digits instead of 4.

This should work:

NSString *s = [NSString stringWithUTF8String:"\u0627\u0644\u0641\u0631\u0646"]; 
like image 136
David Gelhar Avatar answered Oct 14 '22 03:10

David Gelhar