Java删除开头和末尾字符串
//扩展2个String方法
/*
* 删除开头字符串
*/
public static String trimstart(String inStr, String prefix) {
if (inStr.startsWith(prefix)) {
return (inStr.substring(prefix.length()));
}
return inStr;
}
/*
* 删除末尾字符串
*/
public static String trimend(String inStr, String suffix) {
if (inStr.endsWith(suffix)) {
return (inStr.substring(0,inStr.length()-suffix.length()));
}
return inStr;
}
public static void main(String[] args) {
String testStr1 = ",1,2,3";
System.out.println("trimstart的结果:"+trimstart(testStr1,","));
String testStr2 = "1,2,3,";
System.out.println("trimend的结果:"+trimend(testStr2,","));
}