Java 把字符串括号里的内容提取出来

论坛 期权论坛 脚本     
匿名网站用户   2020-12-21 05:17   534   0
public static void main(String args[]){
String str="您好{options{abc}}评论了您的{options{def}}";
ArrayList<String> word=new ArrayList<String>();
int m=0,n=0;
int count=0;
for(int i=0;i<str.length();i++){
if(str.charAt(i)=='{'){
if(count==0){
m=i;
}
count++;
}
if(str.charAt(i)=='}'){
count--;
if(count==0){
n=i;
word.add(str.substring(m,n+1));
}
}
}
for(String a : word){
System.out.println(a);
}
}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP