简体   繁体   中英

Concatenate \u sign with a string in iOS

I can't figure out how to concatenate Unicode sign \\u\u003c/code> with string like f1bc properly to get \ . Any ideas how to do it?

Reason: The API I currently use sends me Unicode signs without \\u\u003c/code> ... Response looks like this (one from NSDictionary keys):

"icon" : "f1bc",

Accoring to your comment, you cannot do that with concatenating \\u and the hex code. This is interpreted at compile time.

You have to get the unicode value first and then transform it into the character:

NSString* unicodeString = …; // @"f1bc"
NSScanner *scanner = [NSScanner scannerWithString:unicodeString];
unsigned unicode;
[scanner scanHexInt:&unicode];
NSString *stringWithUnicodeChar = [NSString stringWithFormat:@"%C", (unichar)unicode];

Typped in Safari.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM