I am working with the Google Place API and got a successful JSON response. But one NSString
is L\U00c3\U00b6wenbr\U00c3\U00a4u Keller
. I want to convert it into a proper NSString
like Lowenbrau Keller
. How can I do this conversion?
The correct format is to use a lowercase u to denote unicode in Coocoa:
Wrong:
NSString *string1 = @"L\U00c3\U00b6wenbr\U00c3\U00a4u Keller";
Correct:
NSString *string2 = @"L\u00c3\u00b6wenbr\u00c3\u00a4u Keller";
To get it to print correctly replace \u00 with \x
NSString *string3 = @"L\xc3\xb6wenbr\xc3\xa4u Keller";
NSLog(@"string3: '%@'", string4);
NSLog output: string3: 'Löwenbräu Keller'
TESTED CODE:100 % WORKS
NOTE:
\U and \u are not the same thing. The \U escape expects 8 (hex) digits instead of 4.
NSString *inputString =@"L\u00c3\u00b6wenbr\u00c3\u00a4u Keller";
NSString *outputString=[[NSString stringWithFormat:@"%@",inputString] stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:[NSLocale currentLocale]];
NSLog(@"outputString : %@ \n\n",outputString);
OUTPUT:
outputString : LA¶wenbrA¤u Keller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With