Objective C HTML escape/unescape

前端 未结 14 2124
生来不讨喜
生来不讨喜 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 16:54

    Check out my NSString category for XMLEntities. There's methods to decode XML entities (including all HTML character references), encode XML entities, stripping tags and removing newlines and whitespace from a string:

    - (NSString *)stringByStrippingTags;
    - (NSString *)stringByDecodingXMLEntities; // Including all HTML character references
    - (NSString *)stringByEncodingXMLEntities;
    - (NSString *)stringWithNewLinesAsBRs;
    - (NSString *)stringByRemovingNewLinesAndWhitespace;
    

提交回复
热议问题