我有:
NSString = @"%3Cfont+color%3D%22%23660000%22%3EBeta1%3C%2Ffont%3E++%3Cfont+color%3D%22%23000000%22%3Ebeta3%3C%2Ffont%3E"
如何将此Hex HTML字符串转换为NSSting
或HTML字符串,以便我可以使用其字体和颜色属性以及获取文本?
答案 0 :(得分:0)
字符串看起来乍一看是编码的,所以:
NSString *input = @"%3Cfont+color%3D%22%23660000%22%3EBeta1%3C%2Ffont%3E++%3Cfont+color%3D%22%23000000%22%3Ebeta3%3C%2Ffont%3E";
NSString *result = [input stringByReplacingOccurrencesOfString:@"+" withString:@" "];
result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", result);
然后将html解析为NSAttributedString
NSAttributedString *as = [NSAttributedString attributedStringWithHTML:result];
(在iOS上使用DTCoreText库进行HTML解析)