我有以下 xml 片段作为字符串:
String str ="<xs:user>userName</xs:user><xs:password>userPassword</xs:password>
<xs:address>addressString</xs:address>";
将 userPassword 替换为 xxxxxxx 的最佳方法是什么?
编辑:xs(命名空间)可能会有所不同。
最佳答案
尝试使用这个:
String str2 = str.replaceFirst("<xs:password>.*?</xs:password>", "<xs:password>xxxxxxxxxx</xs:password>");`
关于java - 查找并替换两个模式字符串之间的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23007973/