例:

”CPAPP:{220|1220|18888888888|628888888888}”

1.截取字符串,以“:{”为分隔符

String c=str.split("\\:\\{")[1];//获取:{后面的所有字符串,注意"\\:\\{"

2.截取里面手机号

String smsisdn=c.split("\\|")[2];//注意,split将会把字符串中所有含有分隔符的,分拆后存在数组中,所以只需按照数组下标获取即可

3,截取,substring

String s=c,substring("首","尾");//从0开始算

4.统计在字符串中出现某个字符的数量

String str=”CPAPP:{220|1220|18888888888|628888888888}”;

char s='|';   //判断str中出现|的数量

char[] chs = str.toCharArray();
// 定义变量count存储字符串出现次数
int count = 0;
for(int i = 0;i < chs.length;i++) {
if(chs[i] == s) {
count++;
}
}
return count;

 

5  判断字符串中是否包含特定字符

 boolean l=str.contains(":{"))

 

 

 

未完,待补充!

 

posted on 2017-11-20 16:45  我想长点脑子  阅读(4393)  评论(0编辑  收藏  举报