Encode NSString for XML/HTML

后端 未结 14 1387
误落风尘
误落风尘 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:04

    Use the message in the example below :

    anyStringConverted = [anyString stringByReplacingOccurrencesOfString:@"\n" withString:@"
    "];

    This converts 'new line' command to corresponding html code. But to convert symbols, you have to write the corresponding html number. You can see the complete list of html numbers here at

    http://www.ascii.cl/htmlcodes.htm

提交回复
热议问题