public static String trim(String source, char c){
String beTrim = String.valueOf(c);source = source.trim(); // 循环去掉字符串首的beTrim字符
String beginChar = source.substring(0, 1);while (beginChar.equalsIgnoreCase(beTrim)) {
source = source.substring(1, source.length());
beginChar = source.substring(0, 1);
}
// 循环去掉字符串尾的beTrim字符
String endChar = source.substring(source.length() - 1, source.length());
while (endChar.equalsIgnoreCase(beTrim)) {
source = source.substring(0, source.length() - 1);
endChar = source.substring(source.length() - 1, source.length());
}
return source;
本文介绍了一个用于去除Java字符串两端指定字符的方法,通过循环移除首尾重复字符,实现字符串的精简。
1625

被折叠的 条评论
为什么被折叠?



