String 字符串相关常用方法
- 剪切字符串,获得start和end子串之间的字符串
public static String cutBetween(String src,String start,String end){
int i=src.indexOf(start);
if(i==-1)return null;
int j=src.indexOf(end,i+start.length());
if(j==-1)return null;
return src.substring(i+start.length(),j);
}
public static String getAfter(String src,String spilt){
int i=src.indexOf(spilt);
if(i==-1)return null;
return src.substring(i+spilt.length());
}
public static String getBefore(String src,String spilt){
int i=src.indexOf(spilt);
if(i==-1)return null;
return src.substring(0,i);
}
public static float matches(String a,String b){
if(a.equals(""))return 1;
char[]chs= a.toCharArray();
int count=0;
for(char c:chs){
if(b.contains(c+""))count++;
}
return (float)count/a.length();
}
DateFormat formatter = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
Date d = (Date)formatter.parse(dateTime);