我正在开发一个具有inApp-mail发送功能的iPhone应用程序.到目前为止一直很好,但现在我想避免html注入,因为邮件的某些部分是用户生成的文本.
基本上我搜索这样的东西:
// inits
NSString *sourceString = [NSString stringWithString:@"Hello world! Grüße dich Welt <-- This is in German."];
// ----- THAT'S WHAT I'M LOOKING FOR
// pseudo-code |
// V
NSString *htmlEncodedString = [sourceString htmlEncode];
// log
NSLog(@"source string: %@", sourceString);
NSLog(@"encoded string: %@", htmlEncodedString);
Run Code Online (Sandbox Code Playgroud)
预期的输出
source string: Hello world! Grüße dich Welt <-- This is in German.
encoded string: Hello world! Grüße dich Welt <-- This is in German.
我已经用谷歌搜索并浏览了几个SO的问题和答案,但所有这些似乎与 URL编码有关,而这不是我真正需要的(我试过stringByAddingPercentEscapesUsingEncoding没有运气 - 它创造了%C3%BC 'ü'应该是ü).
一个代码示例真的很棒(纠正我的?)......
- …