@Test public void replaceRedundantBlank() { String str1 = " 你好 呀\n 你在干什么\t\n"; String str2 = CommonUtil.replaceRedundantBlank(str1); Assert.equals(str2, "你好 呀 你在干什么", ErrorCodeDef.SYSTEM_ERROR_10001); System.out.println("去掉字符串str1中的首尾空格，以及多余的空格、换行、制表符号"); }
public static String replaceRedundantBlank(final String str) { String dest = GlobalConstants.BLANK; if (StringUtils.isNotEmpty(str)) { Pattern p = Pattern.compile("\\s{1,}|\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(" "); } return StringUtils.trim(dest); }
CommonUtil { public static String replaceRedundantBlank(final String str) { String dest = GlobalConstants.BLANK; if (StringUtils.isNotEmpty(str)) { Pattern p = Pattern.compile("\\s{1,}|\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(" "); } return StringUtils.trim(dest); } }
CommonUtil { public static String replaceRedundantBlank(final String str) { String dest = GlobalConstants.BLANK; if (StringUtils.isNotEmpty(str)) { Pattern p = Pattern.compile("\\s{1,}|\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(" "); } return StringUtils.trim(dest); }  }
CommonUtil { public static String replaceRedundantBlank(final String str) { String dest = GlobalConstants.BLANK; if (StringUtils.isNotEmpty(str)) { Pattern p = Pattern.compile("\\s{1,}|\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(" "); } return StringUtils.trim(dest); }  static String messageFormat(final String message, final Object... params); static String getTransactionID(); static String getRandomCode(); static String getRandomNumber(final int size); static String getRandomChar(final int size); static String getString(final Object obj); static String notNullStr(final String str); static Date getDate(final Long time); static Integer[] splitId(final String idStr, final String splitor); static Long[] splitIdsByLong(final String idStr, final String splitor); static Integer[] splitId(final String idStr); static boolean wildcardMatch(final Collection<String> rules, final String matchValue); static boolean wildcardMatch(final String rule, final String matchValue); static boolean match(final String rule, final String matchValue); static String removeAllSymbol(final String str); static String replaceAllBlank(final String str); static String replaceRedundantBlank(final String str); static boolean isNotEmpty(final T[] paramTypes); static boolean isEmpty(final T[] paramTypes); }
CommonUtil { public static String replaceRedundantBlank(final String str) { String dest = GlobalConstants.BLANK; if (StringUtils.isNotEmpty(str)) { Pattern p = Pattern.compile("\\s{1,}|\t|\r|\n"); Matcher m = p.matcher(str); dest = m.replaceAll(" "); } return StringUtils.trim(dest); }  static String messageFormat(final String message, final Object... params); static String getTransactionID(); static String getRandomCode(); static String getRandomNumber(final int size); static String getRandomChar(final int size); static String getString(final Object obj); static String notNullStr(final String str); static Date getDate(final Long time); static Integer[] splitId(final String idStr, final String splitor); static Long[] splitIdsByLong(final String idStr, final String splitor); static Integer[] splitId(final String idStr); static boolean wildcardMatch(final Collection<String> rules, final String matchValue); static boolean wildcardMatch(final String rule, final String matchValue); static boolean match(final String rule, final String matchValue); static String removeAllSymbol(final String str); static String replaceAllBlank(final String str); static String replaceRedundantBlank(final String str); static boolean isNotEmpty(final T[] paramTypes); static boolean isEmpty(final T[] paramTypes);  }