我怎么判断下面的字符串中有几个 [] 并且知道其中每个的内容?
String str="[Msgs][0][Phone]"
注意字符串中只是规定格式的字符串,用[]括起来的。不是数组。
[解决办法]
for example
- Java code
String str="[Msgs][0][Phone]"Pattern p = Pattern.compile("\\[(.*?)\\]");Matcher m = p.matcher(str);int count = 0;while (m.find()) { count++; System.out.println(m.group(1));}System.out.println(count);