如何替换“与\“ [英] How to replace " with \"

查看:56
本文介绍了如何替换“与\“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要进行替换,问题是,在replace()中,我必须在\之前加上一个\,这样才能真正进行替换.

I need to do that replacement, the problem is, in replace() I have to put a \ before ", so does to really do a replacement.

str = str.replace("\"", "\"");



这是不可能的:



this is not possible:

str = str.replace("\"", "\\"");



我该如何解决?



How can I solve this?

推荐答案

如果我理解,您想将"替换为\".为此,该行是:

If I understand, you want to replace " with \". To do this the line is:

str = str.replace("\"", "\\\"");



每个字符都被转义.



Each character is escaped.


str = str.Replace("\"", "\\\"");


这篇关于如何替换“与\“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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