Objective C HTML转义转义

Objective C HTML转义转义,第1张

Objective C HTML转义/转义

包含以下解决方案。可可CF具有CFXMLCreateStringByUnescapingEntities函数,但在iPhone上不可用。

@interface MREntitiesConverter : NSObject <NSXMLParserDelegate>{    NSMutableString* resultString;}@property (nonatomic, retain) NSMutableString* resultString;- (NSString*)convertEntitiesInString:(NSString*)s;@end@implementation MREntitiesConverter@synthesize resultString;- (id)init{    if([super init]) {        resultString = [[NSMutableString alloc] init];    }    return self;}- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)s {        [self.resultString appendString:s];}- (NSString*)convertEntitiesInString:(NSString*)s {    if (!s) {        NSLog(@"ERROR : Parameter string is nil");    }    NSString* xmlStr = [NSString stringWithFormat:@"<d>%@</d>", s];    NSData *data = [xmlStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];    NSXMLParser* xmlParse = [[[NSXMLParser alloc] initWithdata:data] autorelease];    [xmlParse setDelegate:self];    [xmlParse parse];    return [NSString stringWithFormat:@"%@",resultString];}- (void)dealloc {    [resultString release];    [super dealloc];}@end


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5566582.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存