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(红色部分)但是长度不一样该怎么截啊?
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(红色部分)但是长度不一样该怎么截啊?
int start = line.indexOf("name:");
int end = line.indexOf(",",start);
str = line.subString(start,end);边界问题你自己考虑
/*
* 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());
}
}
* 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 .....
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);