Encode NSString for XML/HTML

后端 未结 14 1354
误落风尘
误落风尘 2020-11-28 04:25

Is there a way to HTML encode a string (NSString) in Objective-C, something along the lines of Server.HtmlEncode in .NET?

14条回答
  •  遥遥无期
    2020-11-28 05:03

    If you can use NSXMLNode (on OS X) Here is the trick:

    NSString *string = @"test"
    NSXMLNode *textNode = [NSXMLNode textWithStringValue:string];
    NSString *escapedString = [textNode.XMLString];
    

提交回复
热议问题