本帖最后由 ale0012 于 2010-11-01 16:45:10 编辑

解决方案 »

  1.   

    你只注意到有个int indexOf(String str)
    没有注意还有个int indexOf(String str,int fromIndex)
    lastIndexOf也有
      

  2.   


                    String a = "cd1212121212jjk,cd12121212cd12jieie,cd123";
    String[] str = a.split(",");
    for(int i=0; i<str.length; i++){
    if(str[i].startsWith("cd") && str[i].length()  == 5){
    System.out.println(str[i]);
    }
    }
    楼主是这个意思不?
      

  3.   

    2L的兄弟,你误会了,和逗号无关的。。1L和3L的XD,可以给个例子吗。。我菜鸟。。
      

  4.   


    楼主是想这样么?
    String s = "cd1212121212jjk,cd12121212cd12jieie";
    Matcher matcher = Pattern.compile("(cd.)").matcher(s);
    while( matcher.find() ) {
    System.out.println(matcher.group());
    }
      

  5.   


    public class Test {
        public void request(String b,int rows){
            String a = "cd1212121212jjk,cd12121212cd12jieie,cd123";
            String[] c = a.split(b);
            for (int i = 0; i < c.length; i++) {
             if(c[i].length()>0){
      System.out.println((b+c[i]).substring(0,rows));
             }
    }          
    }
        public static void main(String[] args) {
    Test test = new Test();
    test.request("cd", 3);
        }
    }