Java实现在字符串中查找字符串

[复制链接]
查看11 | 回复5 | 2012-2-9 15:40:54 | 显示全部楼层 |阅读模式
String ss = "...qqqq:hello-a;hello-b;hello-c;hello-d,....";
Matcher matcher = Pattern.compile("(hello-[a-z])").matcher(ss);
int index = 0;
while (matcher.find()) {
index++;
if (matcher.group(1).equals("hello-c")) {
break;
}
}
System.out....
回复

使用道具 举报

千问 | 2012-2-9 15:40:54 | 显示全部楼层
把上上面那仁兄的改改,不知合不合适:import java.util.regex.Matcher;import java.util.regex.Pattern;public class Find {public static void main(String[] args) {String ss = "...qqqq:hello-a...
回复

使用道具 举报

千问 | 2012-2-9 15:40:54 | 显示全部楼层
StringTokenizer st = new StringTokenizer("...qqqq:hello-a;hello-b;hello-c;hello-d,....", ";");int count = 1;while(st.hasMoreTokens()){if(st.nextToken().equals("hello-c"))...
回复

使用道具 举报

千问 | 2012-2-9 15:40:54 | 显示全部楼层
char c = str.charAt();括号里面的参数为0-str.length();要查指定的,写个循环判断。...
回复

使用道具 举报

千问 | 2012-2-9 15:40:54 | 显示全部楼层
字符串1.indexOf(字符串2) , 试试看...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行