id: 10010, name: 张三, fullname: love1, mail: [email protected] 
id: 10011, name: 李四, fullname: love2, mail: [email protected] 
id: 10012, name: 王大拿, fullname: love3, mail: [email protected] 
id: 10013, name: 彪哥, fullname: love4, mail: [email protected] 
在list里有这么几个字符串
我想只截取他的name(红色部分)但是长度不一样该怎么截啊?

解决方案 »

  1.   


    int start = line.indexOf("name:");
    int end = line.indexOf(",",start);
    str = line.subString(start,end);边界问题你自己考虑
      

  2.   

    取得一个字符串 然后 str.split(",")[1];就得到name:张三了,然后再s.substring(5)就是你要的了
      

  3.   


    /*
     * Created on July 9 2008
     * 
     * Copyright by 布谷鸟
     */
    package file;
    /**
     * 
     * @author cuckoo
     *
     */
    public class CutString { public static void main(String args[]){
    String str = "id: 10010, name: 张三, fullname: love1, mail: [email protected] ";
    int start = str.indexOf("name:")+"name:".length();
    int end   = str.indexOf(", fullname:");
    String subString = str.substring(start,end);
    System.out.println(subString.trim());
    }
    }
      

  4.   

    /*
     * Created on July 9 2008
     * 
     * Copyright by 布谷鸟
     */
    package file;
    /**
     * 
     * @author cuckoo
     *
     */
    public class CutString { public static void main(String args[]){
    String str = "id: 10010, name: 张三, fullname: love1, mail: [email protected] ";
    int start = str.indexOf("name:")+"name:".length();
    int end   = str.indexOf(", fullname:");
    String subString = str.substring(start,end);
    System.out.println(subString.trim());
    }
    }
    ---------------------------------------------------
    Quietly through .....
      

  5.   


    List<String> list = new ArrayList<String>();
    String str = "id: 10010, name: 张三, fullname: love1, mail: [email protected]";
        StringBuffer sb = new StringBuffer();
            Pattern pattern = Pattern.compile("([\\u4e00-\\u9fa5])");
            Matcher    m = pattern.matcher(str);
            while(m.find()){
                if(m.group(1)!=null && m.group(1)!=""){
                 sb.append(m.group(1));
                }    
            }
            System.out.println(sb);