URL-encoding and HTML-encoding NSStrings

后端 未结 4 1852
滥情空心
滥情空心 2021-01-04 22:14

Is their a method to encode/decode HTML and URL (in Xcode, using Objective-C)?

[NSString stringWithContentsOfFile:<#(NSString *)path#> encoding:<#(         


        
4条回答
  •  天命终不由人
    2021-01-04 22:53

    To do HTML/XML entity encoding, you can use a CFMutableString function:

    NSString *result = .....;
    CFStringTransform((CFMutableStringRef)result, NULL, kCFStringTransformToXMLHex, false);

    By setting the last parameter of CFStringTransform to true, it should work for decoding (hex) entities as well.

提交回复
热议问题