package com.sankuai.dolphin.common.util; public class StringTrimUtils { /** * 删除字符串首尾指定字符 */ public static String customTrim(String str, char c) { char[] chars = str.toCharArray(); int len = chars.length; int st = 0; while ( (st < len) && (chars[st] == c) ){ st ++; } while ( (st < len) && (chars[len-1] == c) ){ len --; } return (st > 0) || (len < chars.length) ? str.substring(st, len) : str; } public static String customLtrim(String str, char c) { char[] chars = str.toCharArray(); int len = chars.length; int st = 0; while ( (st < len) && (chars[st] == c) ){ st ++; } return (st > 0) ? str.substring(st, len) : str; } public static String customRtrim(String str, char c) { char[] chars = str.toCharArray(); int len = chars.length; int st = 0; while ( (st < len) && (chars[len-1] == c) ){ len --; } return (len < chars.length) ? str.substring(st, len) : str; } }