NSString 反斜杠转义
我正在开发一个 iPhone OS 应用程序,该应用程序向 Web 服务发送 xml 请求。为了发送请求,xml 被添加到 NSString 中。执行此操作时,我在 xml 文件中遇到了一些引号 "
和反斜杠 \
的问题,需要转义。是否有需要转义的完整字符列表另外
,是否有一种可接受的转义方法(即将 \
替换为 \\
并将 "
替换为 \"< 我自己创建一个方法的情况吗?
/code>)或者是
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?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有完全回答你的问题,但似乎它可能对第二部分有帮助......
Doesn't fully answer your question, but seems like it might help with the second part...
您可以使用 NSScanner 扫描字符集中的字符,如果找到,它将添加转义
\\
到新字符串,并从找到的特殊字符复制下一个子字符串直到下一个。You can use a NSScanner that will scan for characters from a character set and if found, it will add the escaping
\\
to a new string and copy the next substring from the found special character till the next.