-1
比方说,我有这样的事情:如何查找,替换并将包含xml的字符串拆分为数组?
Sample 1: Your number is <foo>12345</foo> and your code is <foo>29939</foo>.
Sample 2: Your number is <foo attr="x">12345</foo> and your code is <foo>29939</foo>.
我想打破这个字符串转换为字符串数组。
喜欢的东西样品1如下:
array[0] = Your number is
array[1] = 12345
array[2] = and your code is
array[3] = 29939
示例2:
array[0] = Your number is
array[1] = x|12345 (adding attr value to it)
array[2] = and your code is
array[3] = 29939
我找<foo>
带或不带字符串属性,需要相应地打破字符串。
我发现了一种简单的方法,用一些值替换下面的东西。
例如:matcher.replaceAll("bar")
这就造成了像:
Your number is bar and your code is bar
我想看到什么是至关断串入一个数组或列表,每当我看到标签<foo>
的字符串值。
String.split是你需要的 –
嵌套标签可能吗?像'abc def xyz '?如果是这样,他们应该如何处理? –
Pshemo
@ JunedAhsan我不这么认为。 OP需要更像解析这个半xml字符串的内容。 –