如何用字符串中的反斜杠美元替换美元字符 [英] How to replace dollar character with backslash dollar in a string
本文介绍了如何用字符串中的反斜杠美元替换美元字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的字符串:
String str = "aLnx5$bK$#C4EFg";
我想替换所有美元 $
反斜杠美元 \ $
的字符,为了获得:
And I want to replace all the dollar $
characters with backslash dollar \$
, in order to get:
String expectedString = "aLnx5\$bK\$#C4EFg";
推荐答案
String str = "aLnx5$bK$#C4EFg";
str = str.replace("$", "\\$");
这篇关于如何用字符串中的反斜杠美元替换美元字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文