/** * 清除字符串首尾的第一个字符串 * @param str 字符串 * @param character 需要清除的字符 * @return 返回清除后的字符串 */ public static String clearFirstAndLastChar(String str, String character) { if (StringUtil.isNotBlank(str)) { String trim = str.trim(); int index = trim.indexOf(character); if (index == 0) { trim = trim.substring(1); } int lastIndex = trim.lastIndexOf(character); if (lastIndex == (trim.length() - 1)) { trim = trim.substring(0, trim.length() - 1); } return trim; } return ""; }