嗨,我有以下字符串变量-
[ <row id="0">
<test>123abc</test>
<INV>123456789</INV>
</row>
,
<row id="1">
<test>456def</test>
<INV>123456789</INV>
</row>
]
它是一个,xml
但是我将这个内部java
代码作为纯字符串发送-
String check = inXml;
System.out.println("incoming payload is "+check);
check = check.replaceAll(",","");
check = check.replaceAll("\\[", "");
check = check.replaceAll("\\]", "");
我曾经replaceAll
替换“ [”,“,”和“]”,现在我想将测试中的值存储在单独的字符串中,例如String s = 123abc,456def
您应该使用解析器。但是,如果您不想要,可以编写一个正则表达式为您提取值,例如:
String line = <yout_html_string>
Pattern p = Pattern.compile("<test>(.*?)</test>");
Matcher m = p.matcher(line);
while (m.find()) {
// m.group(1) is the text you want
// store it in a variable
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句