unicode到字符串转换swift

时间:2017-12-04 11:34:50

标签: ios swift string unicode

hide

我想将所有unicode从上面的字符串转换为字符串。

1 个答案:

答案 0 :(得分:0)

我们的项目中有以下方法:

- (NSString *)convertHTMLToUnicode {
    NSArray *theHTMLEntities = @[@"&", @"Ä", /* more stuff */];
    NSArray *theUnicodeEntities = @[@"&", @"Ä", /* more stuff */];

    NSDictionary *theHTMLSource = [NSDictionary dictionaryWithObjects:theUnicodeEntities forKeys:theHTMLEntities];
    NSMutableString *theText = [NSMutableString stringWithString:self];
    for (NSString *theHtml in theHTMLEntities) {
        [theText replaceOccurrencesOfString:theHtml
                             withString:[theHTMLSource valueForKey:theHtml]
                                options:NSLiteralSearch
                                  range:NSMakeRange(0, theText.length)];
    }
    return theText;
}