HTML character decoding in Objective-C / Cocoa Touch

后端 未结 13 1987
我寻月下人不归
我寻月下人不归 2020-11-22 10:24

First of all, I found this: Objective C HTML escape/unescape, but it doesn\'t work for me.

My encoded characters (come from a RSS feed, btw) look like this: &a

13条回答
  •  无人及你
    2020-11-22 10:59

    If you have the Character Entity Reference as a string, e.g. @"2318", you can extract a recoded NSString with the correct unicode character using strtoul;

    NSString *unicodePoint = @"2318"
    unichar iconChar = (unichar) strtoul(unicodePoint.UTF8String, NULL, 16);
    NSString *recoded = [NSString stringWithFormat:@"%C", iconChar];
    NSLog(@"recoded: %@", recoded");
    // prints out "recoded: ⌘"
    

提交回复
热议问题