/** * 字符串截取之StringBuilder.delete() */ public static void main(String[] args) { StringBuilder str = new StringBuilder("0123456"); System.out.println(str.length()); // 7 System.out.println(str); // 0123456 System.out.println(str.delete(1, 3));// 03456 }
/**TanJiYuan * subStrCut() 此接口用于剔除字符串中指定的字符。 * @param str String目标字符串。目标字符串为任意目标字符串。 * @param strArr String数组,数组内添加要去除的字符。Eg:String strArr [] = {"[","]","'","*","&",","}; * @return */ public static StringBuffer subStrCut(String str , String [] strArr){ int x=0; String stra = ""; String strs = ""; StringBuffer stringBuffer = new StringBuffer(); for(int i=0;i<strArr.length;i++){ if(x==0){ for(int j=0;j<str.length();j++){ if(strArr[i].charAt(0) != str.charAt(j)){ stra += str.charAt(j); } if(j==str.length()-1){ x++; } } } else if(x%2 == 1){ for(int j=0;j<stra.length();j++){ if(strArr[i].charAt(0) != stra.charAt(j)){ strs += stra.charAt(j); } if(j==stra.length()-1){ x++; stra = ""; } } } else if(x%2 == 0){ for(int j=0;j<strs.length();j++){ if(strArr[i].charAt(0) != strs.charAt(j)){ stra += strs.charAt(j); } if(j==strs.length()-1){ x++; strs = ""; } } } } if(stra != ""){ stringBuffer.append(stra); } else { stringBuffer.append(strs); } return stringBuffer; }