NSString反斜杠转义 [英] NSString Backslash escaping

查看:136
本文介绍了NSString反斜杠转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个向Web服务发送xml请求的iPhone OS应用程序。为了发送请求,xml被添加到NSString。这样做时,我在xml文件中遇到了引号和反斜杠 \ 的问题,这些都是必需的是否存在需要转义的完整字符列表?

I am working on an iPhone OS application that sends an xml request to a webservice. In order to send the request, the xml is added to an NSString. When doing this I have experienced some trouble with quotation marks " and backslashes \ in the xml file, which have required escaping. Is there a complete list of characters that need to be escaped?

此外,是否有一种可接受的方式进行转义(即替换 \ \\ \\ \\)或是自己创建方法的情况?

Also, is there an accepted way of doing this escaping (ie replacing \ with \\ and " with \") or is it a case of creating a method myself?

谢谢

推荐答案

NSString *escapedString = [unescapedString stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
escapedString = [escapedString stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

没有完全回答你的问题,但似乎对第二部分有帮助......

Doesn't fully answer your question, but seems like it might help with the second part...

这篇关于NSString反斜杠转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆