Objective C HTML escape/unescape

前端 未结 14 2078
生来不讨喜
生来不讨喜 2020-11-22 16:19

Wondering if there is an easy way to do a simple HTML escape/unescape in Objective C. What I want is something like this psuedo code:

NSString *string = @\"         


        
14条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 17:11

    This is an easy to use NSString category implementation:

    • http://code.google.com/p/qrcode-scanner-live/source/browse/trunk/iphone/Classes/NSString%2BHTML.h
    • http://code.google.com/p/qrcode-scanner-live/source/browse/trunk/iphone/Classes/NSString%2BHTML.m

    It is far from complete but you can add some missing entities from here: http://code.google.com/p/statz/source/browse/trunk/NSString%2BHTML.m

    Usage:

    #import "NSString+HTML.h"
    
    NSString *raw = [NSString stringWithFormat:@"
    "]; NSString *escaped = [raw htmlEscapedString];

提交回复
热议问题