Java tutorial
/* * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package io.manasobi.utils; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang3.CharUtils; /** * ? , , , ? ? ? .<br><br> * Spring? StringUtils, commons-lang3? StringUtils? ? ? . * * @author manasobi * @since 1.0.0 */ public final class StringUtils { private StringUtils() { } public static final String DEFAULT_EMPTY_STRING = ""; /** UTF-8 1? ? */ private static final int ONE_BYTE = 0x00007F; /** UTF-8 2? ? */ private static final int TWO_BYTE = 0x0007FF; /** UTF-8 3? ? */ private static final int THREE_BYTE = 0x00FFFF; public static final String EMPTY = ""; public static final int INDEX_NOT_FOUND = -1; /** ? ? INT*/ private static final int HEX_TO_STRING_INT = 16; /** * ?? "" ?? ? ?? ? 4 .<br> * * <pre> * StringUtils.abbreviate(null, *) = null * StringUtils.abbreviate("", 4) = "" * StringUtils.abbreviate("abcdefg", 6) = "abc..." * StringUtils.abbreviate("abcdefg", 7) = "abcdefg" * StringUtils.abbreviate("abcdefg", 8) = "abcdefg" * StringUtils.abbreviate("abcdefg", 4) = "a..." * StringUtils.abbreviate("abcdefg", 3) = IllegalArgumentException * </pre> * * @param str ? * @param maxWidth ? * @return ?, ?? null? <code>null</code> */ public static String abbreviate(String str, int maxWidth) { return StringUtils.abbreviate(str, maxWidth); } /** * ?? "" ?? ? ?? / .<br> * * <pre> * StringUtils.abbreviate(null, *, *) = null * StringUtils.abbreviate("", 0, 4) = "" * StringUtils.abbreviate("abcdefghijklmno", -1, 10) = "abcdefg..." * StringUtils.abbreviate("abcdefghijklmno", 0, 10) = "abcdefg..." * StringUtils.abbreviate("abcdefghijklmno", 1, 10) = "abcdefg..." * StringUtils.abbreviate("abcdefghijklmno", 4, 10) = "abcdefg..." * StringUtils.abbreviate("abcdefghijklmno", 5, 10) = "...fghi..." * StringUtils.abbreviate("abcdefghijklmno", 6, 10) = "...ghij..." * StringUtils.abbreviate("abcdefghijklmno", 8, 10) = "...ijklmno" * StringUtils.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno" * StringUtils.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno" * StringUtils.abbreviate("abcdefghij", 0, 3) = IllegalArgumentException * StringUtils.abbreviate("abcdefghij", 5, 6) = IllegalArgumentException * </pre> * * @param str ? * @param offset left edge of source String * @param maxWidth ? * @return ?, ?? null? <code>null</code> */ public static String abbreviate(String str, int offset, int maxWidth) { return StringUtils.abbreviate(str, offset, maxWidth); } /** * ?? ? ? .<br> * * <pre> * StringUtils.abbreviateMiddle(null, null, 0) = null * StringUtils.abbreviateMiddle("abc", null, 0) = "abc" * StringUtils.abbreviateMiddle("abc", ".", 0) = "abc" * StringUtils.abbreviateMiddle("abc", ".", 3) = "abc" * StringUtils.abbreviateMiddle("abcdef", ".", 4) = "ab.f" * </pre> * * @param str ? * @param middle ? * @param length ? * @return ? */ public static String abbreviateMiddle(String str, String middle, int length) { return StringUtils.abbreviateMiddle(str, middle, length); } /** * ? ? ? .<br> * * <pre> * StringUtils.capitalize(null) = null * StringUtils.capitalize("") = "" * StringUtils.capitalize("cat") = "Cat" * StringUtils.capitalize("cAt") = "CAt" * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String capitalize(String str) { return StringUtils.capitalize(str); } /** * ?? ? ? ??? ? ? ? .<br> * * <pre> * StringUtils.center(null, *) = null * StringUtils.center("", 4) = " " * StringUtils.center("ab", -1) = "ab" * StringUtils.center("ab", 4) = " ab " * StringUtils.center("abcd", 2) = "abcd" * StringUtils.center("a", 4) = " a " * </pre> * * @param str ? * @param size ? * @return ?, ?? null? <code>null</code> */ public static String center(String str, int size) { return StringUtils.center(str, size); } /** * ?? ? ? ??? ? ? ? .<br> * * <pre> * StringUtils.center(null, *, *) = null * StringUtils.center("", 4, ' ') = " " * StringUtils.center("ab", -1, ' ') = "ab" * StringUtils.center("ab", 4, ' ') = " ab" * StringUtils.center("abcd", 2, ' ') = "abcd" * StringUtils.center("a", 4, ' ') = " a " * StringUtils.center("a", 4, 'y') = "yayy" * </pre> * * @param str ? * @param size ? * @param padChar ? * @return ?, ?? null? <code>null</code> */ public static String center(String str, int size, char padChar) { return StringUtils.center(str, size, padChar); } /** * ?? ? ? ??? ? ? ?? .<br> * * <pre> * StringUtils.center(null, *, *) = null * StringUtils.center("", 4, " ") = " " * StringUtils.center("ab", -1, " ") = "ab" * StringUtils.center("ab", 4, " ") = " ab" * StringUtils.center("abcd", 2, " ") = "abcd" * StringUtils.center("a", 4, " ") = " a " * StringUtils.center("a", 4, "yz") = "yayz" * StringUtils.center("abc", 7, null) = " abc " * StringUtils.center("abc", 7, "") = " abc " * </pre> * * @param str ? * @param size ? * @param padStr ? * @return ?, ?? null? <code>null</code> */ public static String center(String str, int size, String padStr) { return StringUtils.center(str, size, padStr); } /** * ? ??? "<code>\n</code>",<br> * "<code>\r</code>", or "<code>\r\n</code>"? .<br> * * <pre> * StringUtils.chomp(null) = null * StringUtils.chomp("") = "" * StringUtils.chomp("abc \r") = "abc " * StringUtils.chomp("abc\n") = "abc" * StringUtils.chomp("abc\r\n") = "abc" * StringUtils.chomp("abc\r\n\r\n") = "abc\r\n" * StringUtils.chomp("abc\n\r") = "abc\n" * StringUtils.chomp("abc\n\rabc") = "abc\n\rabc" * StringUtils.chomp("\r") = "" * StringUtils.chomp("\n") = "" * StringUtils.chomp("\r\n") = "" * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String chomp(String str) { return StringUtils.chomp(str); } /** * ? ??? ? ? .<br> * * <pre> * StringUtils.chomp(null, *) = null * StringUtils.chomp("", *) = "" * StringUtils.chomp("foobar", "bar") = "foo" * StringUtils.chomp("foobar", "baz") = "foobar" * StringUtils.chomp("foo", "foo") = "" * StringUtils.chomp("foo ", "foo") = "foo " * StringUtils.chomp(" foo", "foo") = " " * StringUtils.chomp("foo", "foooo") = "foo" * StringUtils.chomp("foo", "") = "foo" * StringUtils.chomp("foo", null) = "foo" * </pre> * * @param str ? * @param separator ? * @return ?, ?? null? <code>null</code> */ public static String chomp(String str, String separator) { return StringUtils.chomp(str, separator); } /** * ? ??? ? .<br> * * <pre> * StringUtils.chop(null) = null * StringUtils.chop("") = "" * StringUtils.chop("abc \r") = "abc " * StringUtils.chop("abc\n") = "abc" * StringUtils.chop("abc\r\n") = "abc" * StringUtils.chop("abc") = "ab" * StringUtils.chop("abc\nabc") = "abc\nab" * StringUtils.chop("a") = "" * StringUtils.chop("\r") = "" * StringUtils.chop("\n") = "" * StringUtils.chop("\r\n") = "" * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String chop(String str) { return StringUtils.chop(str); } /** * ? ?.<br><br> * * StringUtils.compareTo("Anyframe Java Test", "Anyframe Java Test") = 0 * * @param sourceStr 1 * @param anotherStr 2 * @return ? ? 0 * 1? 2 ? 0 * 1? 2 ? 0 * @see String#compareTo(String) */ public static int compareTo(String sourceStr, String anotherStr) { if (sourceStr == null || anotherStr == null) { return -1; } return sourceStr.compareTo(anotherStr); } /** * ? ? ?.<br><br> * * StringUtils.compareToIgnoreCase("anyframe java test", "Anyframe Java Test") = 0 * * @param sourceStr 1 * @param anotherStr 2 * @return ? ? 0 * 1? 2 ? 0 * 1? 2 ? 0 * @see String#compareToIgnoreCase(String) */ public static int compareToIgnoreCase(String sourceStr, String anotherStr) { if (sourceStr == null || anotherStr == null) { return -1; } return sourceStr.compareToIgnoreCase(anotherStr); } /** * ? ? ? ? ?.<br> * * <code>null</code> ? ? <code>false</code> .<br> * * <pre> * StringUtils.contains(null, *) = false * StringUtils.contains("", *) = false * StringUtils.contains("abc", 'a') = true * StringUtils.contains("abc", 'z') = false * </pre> * * @param str ? * @param searchChar ? * @return ? ?? true , * ?? ?? <code>null</code>? false */ public static boolean contains(String str, char searchChar) { return StringUtils.contains(str, searchChar); } /** * ? ? ?? ? ?.<br> * * <code>null</code>? <code>false</code> .<br> * * <pre> * StringUtils.contains(null, *) = false * StringUtils.contains(*, null) = false * StringUtils.contains("", "") = true * StringUtils.contains("abc", "") = true * StringUtils.contains("abc", "a") = true * StringUtils.contains("abc", "z") = false * </pre> * * @param str ? * @param searchStr ? * @return ? ?? true , * ?? ?? <code>null</code>? false */ public static boolean contains(String str, String searchStr) { return StringUtils.contains(str, searchStr); } /** * ? ? ?? ? ? ?.<br> * * <code>null</code>? <code>false</code> .<br> * * <pre> * StringUtils.containsIgnoreCase(null, *) = false * StringUtils.containsIgnoreCase(*, null) = false * StringUtils.containsIgnoreCase("", "") = true * StringUtils.containsIgnoreCase("abc", "") = true * StringUtils.containsIgnoreCase("abc", "a") = true * StringUtils.containsIgnoreCase("abc", "z") = false * StringUtils.containsIgnoreCase("abc", "A") = true * StringUtils.containsIgnoreCase("abc", "Z") = false * </pre> * * @param str ? * @param searchStr ? * @return ? ?? true , * ?? ?? <code>null</code>? false */ public static boolean containsIgnoreCase(String str, String searchStr) { return StringUtils.containsIgnoreCase(str, searchStr); } /** * ? ?? character? ? ?<br><br> * * StringUtils.containsInvalidChars("abc/", new char[] { '*', '/' }) = true * * @param str ? * @param invalidChars ? ? * @return ?? ?? ?? ? true */ public static boolean containsInvalidChars(String str, char[] invalidChars) { if (str == null || invalidChars == null) { return false; } int strSize = str.length(); int validSize = invalidChars.length; for (int i = 0; i < strSize; i++) { char ch = str.charAt(i); for (int j = 0; j < validSize; j++) { if (invalidChars[j] == ch) { return true; } } } return false; } /** * ? ?? character? ? ?<br><br> * * StringUtils.containsInvalidChars("abc*abc", "*") = true * * @param str ? * @param invalidChars ? ? * @return ?? ?? ?? ? true */ public static boolean containsInvalidChars(String str, String invalidChars) { if (str == null || invalidChars == null) { return true; } return containsInvalidChars(str, invalidChars.toCharArray()); } /** * ? ?? ? character ?? ?<br><br> * * StringUtils.containsMaxSequence("abbbbc", "4") = true * * @param str ? * @param maxSeqNumber ? ? ? * @return ? ? ? ? true */ public static boolean containsMaxSequence(String str, String maxSeqNumber) { int occurence = 1; int max = Integer.valueOf(maxSeqNumber); if (str == null) { return false; } int sz = str.length(); for (int i = 0; i < (sz - 1); i++) { if (str.charAt(i) == str.charAt(i + 1)) { occurence++; if (occurence == max) { return true; } } else { occurence = 1; } } return false; } /** * ? underscore ? ?? camel case <br><br> * * StringUtils.convertToCamelCase("anyframe_java_test") = "anyframeJavaTest" * * @param underscore underscore ? ? * @return camel case ? ? */ public static String convertToCamelCase(String underscore) { return convertToCamelCase(underscore, "_"); } /** * char? ? ? ?? camel case <br><br> * * StringUtils.convertToCamelCase("anyframe-java-test", "-") = "anyframeJavaTest" * * @param targetString ? ? * @param posChar ?? ? ? * @return camel case ? ? */ public static String convertToCamelCase(String targetString, String posChar) { StringBuilder result = new StringBuilder(); boolean nextUpper = false; String allLower = targetString.toLowerCase(); for (int i = 0; i < allLower.length(); i++) { char currentChar = allLower.charAt(i); if (currentChar == CharUtils.toChar(posChar)) { nextUpper = true; } else { if (nextUpper) { currentChar = Character.toUpperCase(currentChar); nextUpper = false; } result.append(currentChar); } } return result.toString(); } /** * camel case ? ?? underscore ? ? <br><br> * * StringUtils.convertToUnderScore("anyframeJavaTest") = "anyframe_java_test" * * @param camelCase camel case ? ? * @return underscore ? ? */ public static String convertToUnderScore(String camelCase) { String result = ""; for (int i = 0; i < camelCase.length(); i++) { char currentChar = camelCase.charAt(i); // This is starting at 1 so the result does not end up with an // underscore at the begin of the value if (i > 0 && Character.isUpperCase(currentChar)) { result = result.concat("_"); } result = result.concat(Character.toString(currentChar).toLowerCase()); } return result; } /** * ?? ?? ?? .<br> * * <pre> * StringUtils.countMatches(null, *) = 0 * StringUtils.countMatches("", *) = 0 * StringUtils.countMatches("abba", null) = 0 * StringUtils.countMatches("abba", "") = 0 * StringUtils.countMatches("abba", "a") = 2 * StringUtils.countMatches("abba", "ab") = 1 * StringUtils.countMatches("abba", "xxx") = 0 * </pre> * * @param str ? * @param sub ? * @return ?, ?? null? <code>null</code> */ public static int countMatches(String str, String sub) { return StringUtils.countMatches(str, sub); } /** * String ?(sub)? ? String ?(main)? . - ? <br> * ? . + , "aa" "aaa"? ? ? ?, <br> * . <br><br> * * StringUtils.countPattern("aaa", "aa") = 1 * * @param str * the String to check * @param pattern * the pattern to count * @return the number of occurrences */ public static int countPattern(String str, String pattern) { if (str == null || pattern == null || "".equals(pattern)) { return 0; } int count = 0; int pos = 0; while (str.indexOf(pattern, pos) != -1) { int index = str.indexOf(pattern, pos); count++; pos = index + pattern.length(); } return count; } /** * ? ? ?? ? ?? ?? .<br><br> * * StringUtils.decode("Java", "Test", "Good", "Bad") = "bad" * * @param source ? * @param target ? ? * @param result ? ?? ? ? * @param base ? ?? ? * @return ? ?? ?? ?? */ public static String decode(String source, String target, String result, String base) { if (source == null && target == null) { return result; } else if (source == null && target != null) { return base; } else if (source.trim().equals(target)) { return result; } return base; } /** * ?? <code>null</code> ? ? ? ? <code>defaultStr</code>? <br> * <code>str</code>? .<br> * * <pre> * StringUtils.defaultIfBlank(null, "NULL") = "NULL" * StringUtils.defaultIfBlank("", "NULL") = "NULL" * StringUtils.defaultIfBlank(" ", "NULL") = "NULL" * StringUtils.defaultIfBlank("bat", "NULL") = "bat" * StringUtils.defaultIfBlank("", null) = null * </pre> * @param str ? * @param defaultStr ? * @return ? */ public static String defaultIfBlank(String str, String defaultStr) { return StringUtils.defaultIfBlank(str, defaultStr); } /** * ?? <code>null</code> ? ? <code>defaultStr</code>? <br> * <code>str</code>? .<br> * * <pre> * StringUtils.defaultIfEmpty(null, "NULL") = "NULL" * StringUtils.defaultIfEmpty("", "NULL") = "NULL" * StringUtils.defaultIfEmpty("bat", "NULL") = "bat" * StringUtils.defaultIfEmpty("", null) = null * </pre> * * @param str ? * @param defaultStr ? * @return ? */ public static String defaultIfEmpty(String str, String defaultStr) { return StringUtils.defaultIfEmpty(str, defaultStr); } /** * ?? <code>null</code>? <code>str</code>? .<br> * * <pre> * StringUtils.defaultString(null) = "" * StringUtils.defaultString("") = "" * StringUtils.defaultString("bat") = "bat" * </pre> * * @param str ? * @return ?, ?? null? */ public static String defaultString(String str) { return StringUtils.defaultString(str); } /** * ?? <code>null</code>? <code>defaultStr</code>? <br> * <code>str</code>? .<br> * * <pre> * StringUtils.defaultString(null, "NULL") = "NULL" * StringUtils.defaultString("", "NULL") = "" * StringUtils.defaultString("bat", "NULL") = "bat" * </pre> * * @param str ? * @param defaultStr ? * @return ?, ?? null? ? */ public static String defaultString(String str, String defaultStr) { return StringUtils.defaultString(str, defaultStr); } /** * String ? ? ? ?? character? .<br><br> * * StringUtils.deleteChars("zzAccBxx", "AB") = "zzccxx" * * @param str * the source String to search * @param chars * the char to search for and remove * @return the substring with the char removed if found */ public static String deleteChars(String str, String chars) { if (str == null || chars == null) { return str; } String value = str; for (int i = 0; i < chars.length(); i++) { value = removeChar(value, chars.charAt(i)); } return value; } /** * String ? ? ? . - ? ? <br> * . + ?, ? ?? old ? ? .<br><br> * * StringUtils.deletePattern("aababa", "aba") "aba"<br> * StringUtils.deletePattern("zzABCcc", "ABC") - "zzcc" * * @param str * the source String to search * @param pattern * the String to search for and remove * @return the substring with the string removed if found */ public static String deletePattern(String str, String pattern) { return replacePattern(str, pattern, ""); } /** * ? ? ? .<br> * * <pre> * StringUtils.deleteWhitespace(null) = null * StringUtils.deleteWhitespace("") = "" * StringUtils.deleteWhitespace("abc") = "abc" * StringUtils.deleteWhitespace(" ab c ") = "abc" * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String deleteWhitespace(String str) { return StringUtils.deleteWhitespace(str); } /** * StringTokenizer ? , ?? delimiter ? token ?. <br> * String? null? , null? return. <br> * delimiter null? , String? ? element String[] return.<br><br> * * StringUtils.delimitedStringToStringArray("aaa.bbb.ccc.ddd", "."); = test[0]="aaa", test[1]="bbb"... * * @param str * the silgle String to convert * @param delimiter * delimiter for conversioin * @return array of String values */ public static String[] delimitedStringToStringArray(String str, String delimiter) { if (str == null) { return null; } if (delimiter == null) { return new String[] { str }; } List<String> tokens = new ArrayList<String>(); int pos = 0; while (str.indexOf(delimiter, pos) != -1) { int index = str.indexOf(delimiter, pos); tokens.add(str.substring(pos, index)); pos = index + delimiter.length(); } if (pos <= str.length()) { tokens.add(str.substring(pos)); } return tokens.toArray(new String[tokens.size()]); } /** * ?? ? ? .<br> * * <pre> * StringUtils.difference(null, null) = null * StringUtils.difference("", "") = "" * StringUtils.difference("", "abc") = "abc" * StringUtils.difference("abc", "") = "" * StringUtils.difference("abc", "abc") = "" * StringUtils.difference("ab", "abxyz") = "xyz" * StringUtils.difference("abcde", "abxyz") = "xyz" * StringUtils.difference("abcde", "xyz") = "xyz" * </pre> * * @param str1 ?1 * @param str2 ?2 * @return ? */ public static String difference(String str1, String str2) { return StringUtils.difference(str1, str2); } /** * ?? ? ?? ?.<br> * * <pre> * StringUtils.endsWith(null, null) = true * StringUtils.endsWith(null, "def") = false * StringUtils.endsWith("abcdef", null) = false * StringUtils.endsWith("abcdef", "def") = true * StringUtils.endsWith("ABCDEF", "def") = false * StringUtils.endsWith("ABCDEF", "cde") = false * </pre> * * @param str ? * @param suffix ? * @return ?? ? ?? ? ? * <code>null</code>? <code>true</code> */ public static boolean endsWith(String str, String suffix) { return StringUtils.endsWith(str, suffix); } /** * ?? ? ? ?? ?.<br> * * <pre> * StringUtils.endsWithAny(null, null) = false * StringUtils.endsWithAny(null, new String[] {"abc"}) = false * StringUtils.endsWithAny("abcxyz", null) = false * StringUtils.endsWithAny("abcxyz", new String[] {""}) = true * StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}) = true * StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true * </pre> * * @param string ? * @param searchStrings ? * @return ?? ? ? ?? ? ? * <code>null</code>? <code>true</code> * */ public static boolean endsWithAny(String string, String[] searchStrings) { return StringUtils.endsWithAny(string, searchStrings); } /** * ?? ? ? ? ?? ?.<br> * * <pre> * StringUtils.endsWithIgnoreCase(null, null) = true * StringUtils.endsWithIgnoreCase(null, "def") = false * StringUtils.endsWithIgnoreCase("abcdef", null) = false * StringUtils.endsWithIgnoreCase("abcdef", "def") = true * StringUtils.endsWithIgnoreCase("ABCDEF", "def") = true * StringUtils.endsWithIgnoreCase("ABCDEF", "cde") = false * </pre> * * @param str ? * @param suffix ? * @return ?? ? ? ? ?? ? ? * <code>null</code>? <code>true</code> */ public static boolean endsWithIgnoreCase(String str, String suffix) { return StringUtils.endsWithIgnoreCase(str, suffix); } /** * ?? ?? ? ?.<br> * * <pre> * StringUtils.equals(null, null) = true * StringUtils.equals(null, "abc") = false * StringUtils.equals("abc", null) = false * StringUtils.equals("abc", "abc") = true * StringUtils.equals("abc", "ABC") = false * </pre> * * @param str1 ? * @param str2 ? ? * @return ? ? ?? ? true, false */ public static boolean equals(String str1, String str2) { return StringUtils.equals(str1, str2); } /** * ?? ?? ? ? ? ?.<br> * * <pre> * StringUtils.equalsIgnoreCase(null, null) = true * StringUtils.equalsIgnoreCase(null, "abc") = false * StringUtils.equalsIgnoreCase("abc", null) = false * StringUtils.equalsIgnoreCase("abc", "abc") = true * StringUtils.equalsIgnoreCase("abc", "ABC") = true * </pre> * * @param str1 ? * @param str2 ? ? * @return ? ? ?? ? ? ? true, false */ public static boolean equalsIgnoreCase(String str1, String str2) { return StringUtils.equalsIgnoreCase(str1, str2); } /** * ?? ?? ?.<br> * * <pre> * StringUtils.notEquals(null, null) = false * StringUtils.notEquals(null, "abc") = true * StringUtils.notEquals("abc", null) = true * StringUtils.notEquals("abc", "abc") = false * StringUtils.notEquals("abc", "ABC") = true * </pre> * * @param str1 ? * @param str2 ? ? * @return ? ? ?? ? true, false */ public static boolean notEquals(String str1, String str2) { return !StringUtils.equals(str1, str2); } /** * ?? ?? ? ? ?.<br> * * <pre> * StringUtils.notEqIgnoreCase(null, null) = false * StringUtils.notEqIgnoreCase(null, "abc") = true * StringUtils.notEqIgnoreCase("abc", null) = true * StringUtils.notEqIgnoreCase("abc", "abc") = false * StringUtils.notEqIgnoreCase("abc", "ABC") = false * </pre> * * @param str1 ? * @param str2 ? ? * @return ? ? ?? ? ? ? true, false */ public static boolean notEqIgnoreCase(String str1, String str2) { return !StringUtils.equalsIgnoreCase(str1, str2); } /** * ?? byte ? ? ? ? <br><br> * * StringUtils.getByteLength("Anyframe Java Test") = 18 * * @param str ? * @return ?? byte ? */ public static int getByteLength(String str) { if (str == null) { return -1; } int size = 0; for (int i = 0; i < str.length(); i++) { size += getByteLength(str.charAt(i)); } return size; } private static int getByteLength(char charat) { int charCode = charat; if (charCode <= ONE_BYTE) { return 1; } else if (charCode <= TWO_BYTE) { return 2; } else if (charCode <= THREE_BYTE) { return 3; } else { return 4; } } /** * ? ? ? ?? ?? .<br> * * <pre> * StringUtils.getCommonPrefix(null) = "" * StringUtils.getCommonPrefix(new String[] {}) = "" * StringUtils.getCommonPrefix(new String[] {"abc"}) = "abc" * StringUtils.getCommonPrefix(new String[] {null, null}) = "" * StringUtils.getCommonPrefix(new String[] {"", ""}) = "" * StringUtils.getCommonPrefix(new String[] {"", null}) = "" * StringUtils.getCommonPrefix(new String[] {"abc", null, null}) = "" * StringUtils.getCommonPrefix(new String[] {null, null, "abc"}) = "" * StringUtils.getCommonPrefix(new String[] {"", "abc"}) = "" * StringUtils.getCommonPrefix(new String[] {"abc", ""}) = "" * StringUtils.getCommonPrefix(new String[] {"abc", "abc"}) = "abc" * StringUtils.getCommonPrefix(new String[] {"abc", "a"}) = "a" * StringUtils.getCommonPrefix(new String[] {"ab", "abxyz"}) = "ab" * StringUtils.getCommonPrefix(new String[] {"abcde", "abxyz"}) = "ab" * StringUtils.getCommonPrefix(new String[] {"abcde", "xyz"}) = "" * StringUtils.getCommonPrefix(new String[] {"xyz", "abcde"}) = "" * StringUtils.getCommonPrefix(new String[] {"i am a machine", "i am a robot"}) = "i am a " * </pre> * * @param strs ? * @return ? */ public static String getCommonPrefix(String[] strs) { return StringUtils.getCommonPrefix(strs); } /** * ?? ?? ?? ? <br><br> * * StringUtils.getContainsCount("Anyframe Java Test", "a") = 3 * * @param str ? * @param sub ? * @return ?? ?? ? */ public static int getContainsCount(String str, String sub) { return org.springframework.util.StringUtils.countOccurrencesOf(str, sub); } /** * ? ? ?? ?? ?? <br><br> * * StringUtils.getContainsCountIgnoreCase("Anyframe Java Test", "test") = 1 * * @param str ? * @param sub ? * @return ?? ?? * @see org.springframework.util.StringUtils#countOccurrencesOf(String, * String) */ public static int getContainsCountIgnoreCase(String str, String sub) { return org.springframework.util.StringUtils.countOccurrencesOf(str.toLowerCase(), sub.toLowerCase()); } /** * ? ?? token? ? <br><br> * * StringUtils.getLastString("Anyframe_Java_Test", "_") = "Test" * * @param origStr ? * @param strToken token * @return token? ? ? */ public static String getLastString(String origStr, String strToken) { StringTokenizer str = new StringTokenizer(origStr, strToken); String lastStr = ""; while (str.hasMoreTokens()) { lastStr = str.nextToken(); } return lastStr; } /** * ?1? ?2 ,, ? ? ? .<br> * * <pre> * StringUtils.getLevenshteinDistance(null, *) = IllegalArgumentException * StringUtils.getLevenshteinDistance(*, null) = IllegalArgumentException * StringUtils.getLevenshteinDistance("","") = 0 * StringUtils.getLevenshteinDistance("","a") = 1 * StringUtils.getLevenshteinDistance("aaapppp", "") = 7 * StringUtils.getLevenshteinDistance("frog", "fog") = 1 * StringUtils.getLevenshteinDistance("fly", "ant") = 3 * StringUtils.getLevenshteinDistance("elephant", "hippo") = 7 * StringUtils.getLevenshteinDistance("hippo", "elephant") = 7 * StringUtils.getLevenshteinDistance("hippo", "zzzzzzzz") = 8 * StringUtils.getLevenshteinDistance("hello", "hallo") = 1 * </pre> * * @param s ?1 * @param t ?2 * @return ?1? ?2 ,, ? ? ? */ public static int getLevenshteinDistance(String s, String t) { return StringUtils.getLevenshteinDistance(s, t); } /** * ? ?? token? arraylist <br><br> * * StringUtils.getStringArray("Anyframe/Java/Test", "/") * * @param str ? * @param strToken token * @return token? ? arraylist */ public static String[] getStringArray(String str, String strToken) { if (str.indexOf(strToken) != -1) { StringTokenizer st = new StringTokenizer(str, strToken); String[] stringArray = new String[st.countTokens()]; for (int i = 0; st.hasMoreTokens(); i++) { stringArray[i] = st.nextToken(); } return stringArray; } return new String[] { str }; } /** * ? ?? ,()? List <br><br> * * @param lst ? * @return ,() ? List */ public static List<String> getTokens(String lst) { return getTokens(lst, ","); } /** * ? ?? separator? List <br><br> * * StringUtils.getTokens("Anyframe/Java/Test", "/") * * @param lst ? * @param separator ? * @return ? ? List */ public static List<String> getTokens(String lst, String separator) { List<String> tokens = new ArrayList<String>(); if (lst != null) { StringTokenizer st = new StringTokenizer(lst, separator); while (st.hasMoreTokens()) { String en = st.nextToken().trim(); tokens.add(en); } } return tokens; } /** * ? () * * @param str * the String to convert * @return UniCode String */ public static String hexToString(String str) { String inStr = str; char[] inChar = inStr.toCharArray(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < inChar.length; i += 4) { String hex = str.substring(i, i + 4); sb.append((char) Integer.parseInt(hex, HEX_TO_STRING_INT)); } return sb.toString(); } /** * ? ? ?? ?? ?? .<br> * * <pre> * StringUtils.indexOf(null, *, *) = -1 * StringUtils.indexOf("", *, *) = -1 * StringUtils.indexOf("aabaabaa", 'b', 0) = 2 * StringUtils.indexOf("aabaabaa", 'b', 3) = 5 * StringUtils.indexOf("aabaabaa", 'b', 9) = -1 * StringUtils.indexOf("aabaabaa", 'b', -1) = 2 * </pre> * * @param str ? * @param searchChar ?? * @param startPos ?? * @return null ? ?? INDEX_NOT_FOUND (-1) */ public static int indexOf(String str, char searchChar, int startPos) { return StringUtils.indexOf(str, searchChar, startPos); } /** * ? ? ?? ?? ?? .<br> * * Null ??-1? <br> * ?? 0 <br> * ? ? ?<br> * ? ? ? ?<br> * ?<br> * * <pre> * StringUtils.indexOf(null, *, *) = -1 * StringUtils.indexOf(*, null, *) = -1 * StringUtils.indexOf("", "", 0) = 0 * StringUtils.indexOf("", *, 0) = -1 (except when * = "") * StringUtils.indexOf("aabaabaa", "a", 0) = 0 * StringUtils.indexOf("aabaabaa", "b", 0) = 2 * StringUtils.indexOf("aabaabaa", "ab", 0) = 1 * StringUtils.indexOf("aabaabaa", "b", 3) = 5 * StringUtils.indexOf("aabaabaa", "b", 9) = -1 * StringUtils.indexOf("aabaabaa", "b", -1) = 2 * StringUtils.indexOf("aabaabaa", "", 2) = 2 * StringUtils.indexOf("abc", "", 9) = 3 * </pre> * * @param str ? * @param searchStr ? * @param startPos ?? * @return ?? ?? -1 ? null ? */ public static int indexOf(String str, String searchStr, int startPos) { return StringUtils.indexOf(str, searchStr, startPos); } /** * ? ? ? ? <br> * ? ?? .<br> * * ?? <code>null</code> ? <code>-1</code>? .<br> * ? <code>null</code> ? ? <code>-1</code>? .<br> * ?? ? <code>0</code>? . <br> * * <pre> * StringUtils.indexOfAny(null, *) = -1 * StringUtils.indexOfAny(*, null) = -1 * StringUtils.indexOfAny(*, []) = -1 * StringUtils.indexOfAny("zzabyycdxx", ["ab","cd"]) = 2 * StringUtils.indexOfAny("zzabyycdxx", ["cd","ab"]) = 2 * StringUtils.indexOfAny("zzabyycdxx", ["mn","op"]) = -1 * StringUtils.indexOfAny("zzabyycdxx", ["zab","aby"]) = 1 * StringUtils.indexOfAny("zzabyycdxx", [""]) = 0 * StringUtils.indexOfAny("", [""]) = 0 * StringUtils.indexOfAny("", ["a"]) = -1 * </pre> * * @param str ? * @param searchStrs ? * @return ? ??, ?? -1. */ public static int indexOfAny(String str, String[] searchStrs) { return StringUtils.indexOfAny(str, searchStrs); } /** * ?? ? ? ?? .<br> * * <pre> * StringUtils.indexOfDifference(null, null) = -1 * StringUtils.indexOfDifference("", "") = -1 * StringUtils.indexOfDifference("", "abc") = 0 * StringUtils.indexOfDifference("abc", "") = 0 * StringUtils.indexOfDifference("abc", "abc") = -1 * StringUtils.indexOfDifference("ab", "abxyz") = 2 * StringUtils.indexOfDifference("abcde", "abxyz") = 2 * StringUtils.indexOfDifference("abcde", "xyz") = 0 * </pre> * * @param str1 ?1 * @param str2 ?2 * @return ?, ? -1 */ public static int indexOfDifference(String str1, String str2) { return StringUtils.indexOfDifference(str1, str2); } /** * ? ? ? ? ?? .<br> * * <pre> * StringUtils.indexOfDifference(null) = -1 * StringUtils.indexOfDifference(new String[] {}) = -1 * StringUtils.indexOfDifference(new String[] {"abc"}) = -1 * StringUtils.indexOfDifference(new String[] {null, null}) = -1 * StringUtils.indexOfDifference(new String[] {"", ""}) = -1 * StringUtils.indexOfDifference(new String[] {"", null}) = 0 * StringUtils.indexOfDifference(new String[] {"abc", null, null}) = 0 * StringUtils.indexOfDifference(new String[] {null, null, "abc"}) = 0 * StringUtils.indexOfDifference(new String[] {"", "abc"}) = 0 * StringUtils.indexOfDifference(new String[] {"abc", ""}) = 0 * StringUtils.indexOfDifference(new String[] {"abc", "abc"}) = -1 * StringUtils.indexOfDifference(new String[] {"abc", "a"}) = 1 * StringUtils.indexOfDifference(new String[] {"ab", "abxyz"}) = 2 * StringUtils.indexOfDifference(new String[] {"abcde", "abxyz"}) = 2 * StringUtils.indexOfDifference(new String[] {"abcde", "xyz"}) = 0 * StringUtils.indexOfDifference(new String[] {"xyz", "abcde"}) = 0 * StringUtils.indexOfDifference(new String[] {"i am a machine", "i am a robot"}) = 7 * </pre> * * @param strs ? * @return ?, ? -1 * @since 2.4 */ public static int indexOfDifference(String[] strs) { return StringUtils.indexOfDifference(strs); } /** * ? ? ?? ? ?? ?? ?? ?? .<br><br> * * StringUtils.indexOfIgnoreCase("Anyframe Java Test", "java") = 9 * * @param str ? * @param search ? * @return ?? ?? * @see String#indexOf(String) */ public static int indexOfIgnoreCase(String str, String search) { if (str == null || search == null) { return -1; } return str.toLowerCase().indexOf(search.toLowerCase()); } /** * ? ? ?? ? ? ?? ?? .<br> * * <pre> * StringUtils.indexOfIgnoreCase(null, *, *) = -1 * StringUtils.indexOfIgnoreCase(*, null, *) = -1 * StringUtils.indexOfIgnoreCase("", "", 0) = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 * StringUtils.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 * StringUtils.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 * StringUtils.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 * StringUtils.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 * StringUtils.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 * StringUtils.indexOfIgnoreCase("aabaabaa", "", 2) = 2 * StringUtils.indexOfIgnoreCase("abc", "", 9) = -1 * </pre> * * @param str ? * @param searchStr ? * @param startPos ?? * @return ?? ?? -1 ? null ? */ public static int indexOfIgnoreCase(String str, String searchStr, int startPos) { return StringUtils.indexOfIgnoreCase(str, searchStr, startPos); } /** * ?? ? ?? ?.<br> * * <pre> * StringUtils.isAllLowerCase(null) = false * StringUtils.isAllLowerCase("") = false * StringUtils.isAllLowerCase(" ") = false * StringUtils.isAllLowerCase("abc") = true * StringUtils.isAllLowerCase("abC") = false * </pre> * * @param str ? * @return ?? ? ? ? ?? null? ? <code>true</code> */ public static boolean isAllLowerCase(String str) { return StringUtils.isAllLowerCase(str); } /** * ?? ? ?? ?.<br> * * <pre> * StringUtils.isAllUpperCase(null) = false * StringUtils.isAllUpperCase("") = false * StringUtils.isAllUpperCase(" ") = false * StringUtils.isAllUpperCase("ABC") = true * StringUtils.isAllUpperCase("aBC") = false * </pre> * * @param str ? * @return ?? ? ? ? ?? null? ? <code>true</code> */ public static boolean isAllUpperCase(String str) { return StringUtils.isAllUpperCase(str); } /** * ? ?? ? ? ?<br><br> * * StringUtils.isAlpha("abcfds") = true * * @param str ? * @return ?? ? ?? true */ public static boolean isAlpha(String str) { if (str == null) { return false; } int sz = str.length(); if (sz == 0) { return false; } for (int i = 0; i < sz; i++) { if (!Character.isLetter(str.charAt(i))) { return false; } } return true; } /** * ?? ? ? ? ?? ?.<br> * * <pre> * StringUtils.isAlphanumeric(null) = false * StringUtils.isAlphanumeric("") = true * StringUtils.isAlphanumeric(" ") = false * StringUtils.isAlphanumeric("abc") = true * StringUtils.isAlphanumeric("ab c") = false * StringUtils.isAlphanumeric("ab2c") = true * StringUtils.isAlphanumeric("ab-c") = false * </pre> * * @param str ? * @return ? ? ? ? ?? null? ? <code>true</code> */ public static boolean isAlphanumeric(String str) { return StringUtils.isAlphanumeric(str); } /** * ?? ? ? ? ? ? <br> * ?? ?.<br> * * <pre> * StringUtils.isAlphanumericSpace(null) = false * StringUtils.isAlphanumericSpace("") = true * StringUtils.isAlphanumericSpace(" ") = true * StringUtils.isAlphanumericSpace("abc") = true * StringUtils.isAlphanumericSpace("ab c") = true * StringUtils.isAlphanumericSpace("ab2c") = true * StringUtils.isAlphanumericSpace("ab-c") = false * </pre> * * @param str ? * @return ?? ? ? ? ?? ? ? ?? null? ? <code>true</code> */ public static boolean isAlphanumericSpace(String str) { return StringUtils.isAlphanumericSpace(str); } /** * ?? ? ? ? ??? ?.<br> * * <code>null</code> will return <code>false</code> * An empty String (length()=0) will return <code>true</code>.<br> * * <pre> * StringUtils.isAlphaSpace(null) = false * StringUtils.isAlphaSpace("") = true * StringUtils.isAlphaSpace(" ") = true * StringUtils.isAlphaSpace("abc") = true * StringUtils.isAlphaSpace("ab c") = true * StringUtils.isAlphaSpace("ab2c") = false * StringUtils.isAlphaSpace("ab-c") = false * </pre> * * @param str ? * @return ?? ? ? ?? ? ? ?? null? ? <code>true</code> */ public static boolean isAlphaSpace(String str) { return StringUtils.isAlphaSpace(str); } /** * printable ?? ?.<br> * * <pre> * StringUtils.isAsciiPrintable(null) = false * StringUtils.isAsciiPrintable("") = true * StringUtils.isAsciiPrintable(" ") = true * StringUtils.isAsciiPrintable("Ceki") = true * StringUtils.isAsciiPrintable("ab2c") = true * StringUtils.isAsciiPrintable("!ab-c~") = true * StringUtils.isAsciiPrintable("\u0020") = true * StringUtils.isAsciiPrintable("\u0021") = true * StringUtils.isAsciiPrintable("\u007e") = true * StringUtils.isAsciiPrintable("\u007f") = false * StringUtils.isAsciiPrintable("Ceki G\u00fclc\u00fc") = false * </pre> * * @param str ? * @return ?? ? printable ?? <code>true</code> */ public static boolean isAsciiPrintable(String str) { return StringUtils.isAsciiPrintable(str); } /** * ?? ? NULL? ?.<br> * * <pre> * StringUtils.isBlank(null) = true * StringUtils.isBlank("") = true * StringUtils.isBlank(" ") = true * StringUtils.isBlank("bob") = false * StringUtils.isBlank(" bob ") = false * </pre> * * @param str ? * @return null ? true * ? ? true * ?? false */ public static boolean isBlank(String str) { return StringUtils.isBlank(str); } //? ...?. -> /** * String? '?' ? ?.<br> * ??? ?? Java? ? ? .<br> * String? null? , false return.<br><br> * * StringUtils.isDigit("1234") = true<br> * StringUtils.isDigit("1234A") = false * * @param str * the String to check, may be null * @return true if String contains only digits, false if not or null string * input */ public static boolean isDigit(String str) { if (str == null) { return false; } char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; i++) { if (!Character.isDigit(chars[i])) { return false; } } return true; } /** * ?? null ? ? <br><br> * * StringUtils.isEmpty("") = true * * @param str ? * @return null ? ? true */ public static boolean isEmpty(String str) { return (str == null || str.length() == 0); } // Mid //----------------------------------------------------------------------- /** * trim ?? null ? ? <br><br> * * StringUtils.isEmptyTrimmed(" ") = true * * @param str ? * @return trim ?? null ? ? true */ public static boolean isEmptyTrimmed(String str) { return (str == null || str.trim().length() == 0); } // Mid //----------------------------------------------------------------------- /** * String? ? ? . * * @param str * the String to check, may be null * @param pattern * the pattern to check, may be null * @return true if String contains the given pattern, false if not or null * string input */ public static boolean isFormattedString(String str, String pattern) { if (str == null || pattern == null) { return false; } else { return str.matches(pattern); } } /** * character ?? ?.<br><br> * * StringUtils.isHangul('') = true<br> * StringUtils.isHangul('T') = false * * @param str * the String to check, may be null * @return true if the String contains only Korean Language, false if not */ public static boolean isHangul(char str) { String unicodeBlock = Character.UnicodeBlock.of(str).toString(); return unicodeBlock.equals("HANGUL_JAMO") || unicodeBlock.equals("HANGUL_SYLLABLES") || unicodeBlock.equals("HANGUL_COMPATIBILITY_JAMO"); } /** * String? , ? ? ? ?? ?.<br> * full? true , ? ?.<br> * ' ? ' ? ? ? ? ,<br> * ? ? ? ?? ?.<br> * full? false , ? ?? ?? ?.<br><br> * * StringUtils.isHangul("", true) = true<br> * StringUtils.isHangul("abc", true) = false<br> * StringUtils.isHangul("abc", false) = true<br> * StringUtils.isHangul("abcd", false) = false * * @param str * the String to check, may be null * @param checkForAll * flag for check only Korean characters(true) or any Korean * characters(false) * @return true if the String contains only Korean Language(when checkForAll * is true) or any Korean characters(when checkForAll is false), * false if not */ public static boolean isHangul(String str, boolean checkForAll) { char[] chars = str.toCharArray(); if (!checkForAll) { for (int i = 0; i < chars.length; i++) { if (isHangul(chars[i])) { return true; } } return false; } else { for (int i = 0; i < chars.length; i++) { if (!isHangul(chars[i])) { return false; } } return true; } } /** * String? '?' ? ?.<br> * ??? ?? Java? ? ? .<br> * String? null? , false return.<br><br> * * StringUtils.isLetter("test") = true<br> * StringUtils.isLetter("test")= true<br> * StringUtils.isLetter("test#$%") = false<br> * StringUtils.isLetter("test123") = false * * @param str * the String to check, may be null * @return true if String contains only letters, false if not or null string * input */ public static boolean isLetter(String str) { if (str == null) { return false; } char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; i++) { if (!Character.isLetter(chars[i])) { return false; } } return true; } // Mid //----------------------------------------------------------------------- /** * String? '?' '?' ? ?.<br> * ? ??? ?? Java? ? ? .<br> * String? null? , false return.<br><br> * * StringUtils.isLetterOrDigit("12") = true<br> * StringUtils.isLetterOrDigit("12@#%") = false * * @param str * the String to check, may be null * @return true if String contains only letters or digits, false if not or * null string input */ public static boolean isLetterOrDigit(String str) { if (str == null) { return false; } char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; i++) { if (!Character.isLetterOrDigit(chars[i])) { return false; } } return true; } /** * ?? ? NULL? ?.<br> * * <pre> * StringUtils.isNotBlank(null) = false * StringUtils.isNotBlank("") = false * StringUtils.isNotBlank(" ") = false * StringUtils.isNotBlank("bob") = true * StringUtils.isNotBlank(" bob ") = true * </pre> * * @param str ? * @return null? ? true * ? ? true * ?? false */ public static boolean isNotBlank(String str) { return StringUtils.isNotBlank(str); } // Mid //----------------------------------------------------------------------- /** * ?? null ? ? ? <br><br> * * StringUtils.isNotEmpty("abc") = true * * @param str ? * @return null ? ? ? true */ public static boolean isNotEmpty(String str) { return !isEmpty(str); } /** * ?? ? ?? ? ? ?? .<br><br> * * StringUtils.isNotNumeric("12345") = false<br> * StringUtils.isNumeric("12345ABC") = true * * @param str * the String to check, may be null * @return true if String contains any letters, false if not or null string * input */ public static boolean isNotNumeric(String str) { if (str == null) { return false; } int sz = str.length(); for (int i = 0; i < sz; i++) { if (!Character.isDigit(str.charAt(i))) { return true; } } return false; } // Mid //----------------------------------------------------------------------- /** * ?? ? ?? ?.<br> * * <pre> * StringUtils.isNumeric(null) = false * StringUtils.isNumeric("") = true * StringUtils.isNumeric(" ") = false * StringUtils.isNumeric("123") = true * StringUtils.isNumeric("12 3") = false * StringUtils.isNumeric("ab2c") = false * StringUtils.isNumeric("12-3") = false * StringUtils.isNumeric("12.3") = false * </pre> * * @param str ? * @return ?? ? ? ? ?? null? ?<code>true</code> */ public static boolean isNumeric(String str) { return StringUtils.isNumeric(str); } /** * ?? ? ? ?? ?.<br> * * <pre> * StringUtils.isNumericSpace(null) = false * StringUtils.isNumericSpace("") = true * StringUtils.isNumericSpace(" ") = true * StringUtils.isNumericSpace("123") = true * StringUtils.isNumericSpace("12 3") = true * StringUtils.isNumericSpace("ab2c") = false * StringUtils.isNumericSpace("12-3") = false * StringUtils.isNumericSpace("12.3") = false * </pre> * * @param str ? * @return ?? ? ? ? ? ?? null? ?<code>true</code> */ public static boolean isNumericSpace(String str) { return StringUtils.isNumericSpace(str); } // Mid //----------------------------------------------------------------------- /** * String? Space? .<br> * Space? ? ?, String.trim()? ? ?? .<br> * String? null?, false return.<br><br> * * StringUtils.isSpaceOnly(" ") = true<br> * StringUtils.isSpaceOnly("") = true<br> * StringUtils.isSpaceOnly("test") = false * * @param str * the String to check, may be null * @return true if String contains only whitespace, false if not or null * string input */ public static boolean isSpaceOnly(String str) { if (str == null) { return false; } else { return str.trim().length() <= 0; } } /** * ?? ? ?? ?.<br> * * <pre> * StringUtils.isWhitespace(null) = false * StringUtils.isWhitespace("") = true * StringUtils.isWhitespace(" ") = true * StringUtils.isWhitespace("abc") = false * StringUtils.isWhitespace("ab2c") = false * StringUtils.isWhitespace("ab-c") = false * </pre> * * @param str ? * @return ?? ? ? ? ?? null? ?<code>true</code> */ public static boolean isWhitespace(String str) { return StringUtils.isWhitespace(str); } // Mid //----------------------------------------------------------------------- /** * collection? ?? ? ? .<br> * * @param collection Collection * @param separator ? * @return ?, collection null? <code>null</code> */ @SuppressWarnings("rawtypes") public static String join(Collection collection, char separator) { return StringUtils.join(collection, separator); } // Mid //----------------------------------------------------------------------- /** * collection? ?? ? ? .<br> * * @param collection Collection * @param separator ? * @return ?, collection null? <code>null</code> */ @SuppressWarnings("rawtypes") public static String join(Collection collection, String separator) { return StringUtils.join(collection, separator); } /** * iterator? ?? ? ? .<br> * * @param iterator Iterator * @param separator ? * @return ?, iterator null? <code>null</code> */ @SuppressWarnings("rawtypes") public static String join(Iterator iterator, char separator) { return StringUtils.join(iterator, separator); } // Mid //----------------------------------------------------------------------- /** * iterator? ?? ? ? .<br> * * @param iterator Iterator * @param separator ? * @return ?, iterator null? <code>null</code> */ @SuppressWarnings("rawtypes") public static String join(Iterator iterator, String separator) { return StringUtils.join(iterator, separator); } /** * ? ?? ? ? .<br> * * <pre> * StringUtils.join(null) = null * StringUtils.join([]) = "" * StringUtils.join([null]) = "" * StringUtils.join(["a", "b", "c"]) = "abc" * StringUtils.join([null, "", "a"]) = "a" * </pre> * * @param array * @return ?, ? null? <code>null</code> */ public static String join(Object[] array) { return StringUtils.join(array); } /** * ? ?? ? ? .<br> * * <pre> * StringUtils.join(null, *) = null * StringUtils.join([], *) = "" * StringUtils.join([null], *) = "" * StringUtils.join(["a", "b", "c"], ';') = "a;b;c" * StringUtils.join(["a", "b", "c"], null) = "abc" * StringUtils.join([null, "", "a"], ';') = ";;a" * </pre> * * @param array * @param separator ? * @return ?, ? null? <code>null</code> */ public static String join(Object[] array, char separator) { return StringUtils.join(array, separator); } /** * ? ?? ? ? ?? ???? <br> * ? ??? .<br> * * <pre> * StringUtils.join(null, *) = null * StringUtils.join([], *) = "" * StringUtils.join([null], *) = "" * StringUtils.join(["a", "b", "c"], ';') = "a;b;c" * StringUtils.join(["a", "b", "c"], null) = "abc" * StringUtils.join([null, "", "a"], ';') = ";;a" * </pre> * * @param array * @param separator ? * @param startIndex ?? * @param endIndex ???? * @return ?, ? null? <code>null</code> */ public static String join(Object[] array, char separator, int startIndex, int endIndex) { return StringUtils.join(array, separator, startIndex, endIndex); } /** * ? ?? ? ? ? ??? .<br> * * <pre> * StringUtils.join(null, *) = null * StringUtils.join([], *) = "" * StringUtils.join([null], *) = "" * StringUtils.join(["a", "b", "c"], "--") = "a--b--c" * StringUtils.join(["a", "b", "c"], null) = "abc" * StringUtils.join(["a", "b", "c"], "") = "abc" * StringUtils.join([null, "", "a"], ',') = ",,a" * </pre> * * @param array * @param separator ? * @return ?, ? null? <code>null</code> */ public static String join(Object[] array, String separator) { return StringUtils.join(array, separator); } /** * ? ?? ? ? ?? ???? <br> * ? ??? .<br> * * <pre> * StringUtils.join(null, *) = null * StringUtils.join([], *) = "" * StringUtils.join([null], *) = "" * StringUtils.join(["a", "b", "c"], "--") = "a--b--c" * StringUtils.join(["a", "b", "c"], null) = "abc" * StringUtils.join(["a", "b", "c"], "") = "abc" * StringUtils.join([null, "", "a"], ',') = ",,a" * </pre> * * @param array * @param separator ? * @param startIndex ?? * @param endIndex ???? * @return ?, ? null? <code>null</code> */ public static String join(Object[] array, String separator, int startIndex, int endIndex) { return StringUtils.join(array, separator, startIndex, endIndex); } /** * ? ? ?? ?? .<br> * * <pre> * StringUtils.lastIndexOf(null, *) = -1 * StringUtils.lastIndexOf("", *) = -1 * StringUtils.lastIndexOf("aabaabaa", 'a') = 7 * StringUtils.lastIndexOf("aabaabaa", 'b') = 5 * </pre> * * @param str ? * @param searchChar ? * @return ? ?? -1 ? ? null ? */ public static int lastIndexOf(String str, char searchChar) { return StringUtils.lastIndexOf(str, searchChar); } // Mid //----------------------------------------------------------------------- /** * ? ? ?? ?? ?? .<br> * * <pre> * StringUtils.lastIndexOf(null, *, *) = -1 * StringUtils.lastIndexOf("", *, *) = -1 * StringUtils.lastIndexOf("aabaabaa", 'b', 8) = 5 * StringUtils.lastIndexOf("aabaabaa", 'b', 4) = 2 * StringUtils.lastIndexOf("aabaabaa", 'b', 0) = -1 * StringUtils.lastIndexOf("aabaabaa", 'b', 9) = 5 * StringUtils.lastIndexOf("aabaabaa", 'b', -1) = -1 * StringUtils.lastIndexOf("aabaabaa", 'a', 0) = 0 * </pre> * * @param str ? * @param searchChar ? * @param startPos ?? * @return ? ?? -1 ? ? null ? */ public static int lastIndexOf(String str, char searchChar, int startPos) { return StringUtils.lastIndexOf(str, searchChar, startPos); } /** * ? ? ?? ?? .<br> * * <pre> * StringUtils.lastIndexOf(null, *) = -1 * StringUtils.lastIndexOf(*, null) = -1 * StringUtils.lastIndexOf("", "") = 0 * StringUtils.lastIndexOf("aabaabaa", "a") = 7 * StringUtils.lastIndexOf("aabaabaa", "b") = 5 * StringUtils.lastIndexOf("aabaabaa", "ab") = 4 * StringUtils.lastIndexOf("aabaabaa", "") = 8 * </pre> * * @param str ? * @param searchStr ? * @return ?? ?? -1 ? ? null ? */ public static int lastIndexOf(String str, String searchStr) { return StringUtils.lastIndexOf(str, searchStr); } /** * ? ? ?? ??? .<br> * * <pre> * StringUtils.lastIndexOf(null, *, *) = -1 * StringUtils.lastIndexOf(*, null, *) = -1 * StringUtils.lastIndexOf("aabaabaa", "a", 8) = 7 * StringUtils.lastIndexOf("aabaabaa", "b", 8) = 5 * StringUtils.lastIndexOf("aabaabaa", "ab", 8) = 4 * StringUtils.lastIndexOf("aabaabaa", "b", 9) = 5 * StringUtils.lastIndexOf("aabaabaa", "b", -1) = -1 * StringUtils.lastIndexOf("aabaabaa", "a", 0) = 0 * StringUtils.lastIndexOf("aabaabaa", "b", 0) = -1 * </pre> * * @param str ? * @param searchStr ? * @param startPos ?? * @return ?? ?? -1 ? ? null ? */ public static int lastIndexOf(String str, String searchStr, int startPos) { return StringUtils.lastIndexOf(str, searchStr, startPos); } /** * ? ? ? ? <br> * ? ? ?? .<br> * * ?? <code>null</code> ? <code>-1</code>? .<br> * ? <code>null</code> ? ? <code>-1</code>? .<br> * ?? <code>null</code> ? ? <code>-1</code>? . <br> * * <pre> * StringUtils.lastIndexOfAny(null, *) = -1 * StringUtils.lastIndexOfAny(*, null) = -1 * StringUtils.lastIndexOfAny(*, []) = -1 * StringUtils.lastIndexOfAny(*, [null]) = -1 * StringUtils.lastIndexOfAny("zzabyycdxx", ["ab","cd"]) = 6 * StringUtils.lastIndexOfAny("zzabyycdxx", ["cd","ab"]) = 6 * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1 * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn","op"]) = -1 * StringUtils.lastIndexOfAny("zzabyycdxx", ["mn",""]) = 10 * </pre> * * @param str ? * @param searchStrs ? * @return ? ? ??, ?? -1. */ public static int lastIndexOfAny(String str, String[] searchStrs) { return StringUtils.lastIndexOfAny(str, searchStrs); } /** * ? ? ?? ? ? ? ?? .<br> * * <pre> * StringUtils.lastIndexOfIgnoreCase(null, *) = -1 * StringUtils.lastIndexOfIgnoreCase(*, null) = -1 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A") = 7 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B") = 5 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB") = 4 * </pre> * * @param str ? * @param searchStr ? * @return ?? ?? -1 ? ? null ? */ public static int lastIndexOfIgnoreCase(String str, String searchStr) { return StringUtils.lastIndexOfIgnoreCase(str, searchStr); } /** * ? ? ?? ? ? ?? ?? .<br> * * <pre> * StringUtils.lastIndexOfIgnoreCase(null, *, *) = -1 * StringUtils.lastIndexOfIgnoreCase(*, null, *) = -1 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 8) = 7 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 8) = 5 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB", 8) = 4 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 9) = 5 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", -1) = -1 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 0) = 0 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 0) = -1 * </pre> * * @param str ? * @param searchStr ? * @param startPos ?? * @return ? ??, ?? ? ? ?? null? -1 */ public static int lastIndexOfIgnoreCase(String str, String searchStr, int startPos) { return StringUtils.lastIndexOfIgnoreCase(str, searchStr, startPos); } // Mid //----------------------------------------------------------------------- /** * ? ? ? ?? n ?? .<br> * * <pre> * StringUtils.lastOrdinalIndexOf(null, *, *) = -1 * StringUtils.lastOrdinalIndexOf(*, null, *) = -1 * StringUtils.lastOrdinalIndexOf("", "", *) = 0 * StringUtils.lastOrdinalIndexOf("aabaabaa", "a", 1) = 7 * StringUtils.lastOrdinalIndexOf("aabaabaa", "a", 2) = 6 * StringUtils.lastOrdinalIndexOf("aabaabaa", "b", 1) = 5 * StringUtils.lastOrdinalIndexOf("aabaabaa", "b", 2) = 2 * StringUtils.lastOrdinalIndexOf("aabaabaa", "ab", 1) = 4 * StringUtils.lastOrdinalIndexOf("aabaabaa", "ab", 2) = 1 * StringUtils.lastOrdinalIndexOf("aabaabaa", "", 1) = 8 * StringUtils.lastOrdinalIndexOf("aabaabaa", "", 2) = 8 * </pre> * * * @param str ? * @param searchStr ? * @param ordinal n * @return ?? ?? -1 ? ? null ? */ public static int lastOrdinalIndexOf(String str, String searchStr, int ordinal) { return StringUtils.lastOrdinalIndexOf(str, searchStr, ordinal); } /** * String ?? ?? ? .<br> * ? String? ? ? ? String? .<br> * "..."? ? ?? splitHead() ??.<br><br> * * StringUtils.left("1234567", 3) = "123" * * @param str * the String to get the leftmost characters from, may be null * @param len * the length of the required String * @return the leftmost characters, null if null String input */ public static String left(String str, int len) { if (str == null) { return null; } else if (len <= 0 || str.length() <= len) { return str; } else { return str.substring(0, len); } } /** * ?? ? ?? ? .<br><br> * * StringUtils.leftPad("Anyframe", 12) = " Anyframe" * * @param str ? * @param size ? ?? ? * @return ?? ? ? */ public static String leftPad(String str, int size) { return leftPad(str, size, ' '); } /** * ?? ? ?? ? ? character .<br><br> * * StringUtils.leftPad("Anyframe", 12, 'a') = "aaaaAnyframe" * * @param str ? * @param size ? ?? ? * @param padChar ? ? * @return ?? ? ? */ public static String leftPad(String str, int size, char padChar) { return padChar(str, size, padChar, true); } // Mid //----------------------------------------------------------------------- /** * ?? ? ?? ? ? ? .<br><br> * * StringUtils.leftPad("Anyframe", 12, "Java") = "JavaAnyframe" * * @param str ? * @param size ?? ?? ? * @param padStr ? ? * @return ?? ?? ? */ public static String leftPad(String str, int size, String padStr) { return padString(str, size, padStr, true); } /** * ?? ? ? <br><br> * * StringUtils.leftTrim(" Anyframe Java Test") = "Anyframe Java Test" * * @param str ? * @return ? ? * @see org.springframework.util.StringUtils#trimLeadingWhitespace(String) */ public static String leftTrim(String str) { return org.springframework.util.StringUtils.trimLeadingWhitespace(str); } /** * ?? ? .<br> * * <pre> * StringUtils.lowerCase(null) = null * StringUtils.lowerCase("") = "" * StringUtils.lowerCase("aBc") = "abc" * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String lowerCase(String str) { return StringUtils.lowerCase(str); } /** * ?? ?? ? .<br> * * <pre> * StringUtils.lowerCase(null, Locale.ENGLISH) = null * StringUtils.lowerCase("", Locale.ENGLISH) = "" * StringUtils.lowerCase("aBc", Locale.ENGLISH) = "abc" * </pre> * * @param str ? * @param locale ? * @return ?, ?? null? <code>null</code> */ public static String lowerCase(String str, Locale locale) { return StringUtils.lowerCase(str, locale); } /** * ?? pos ?? len ??? ?? .<br> * * <pre> * StringUtils.mid(null, *, *) = null * StringUtils.mid(*, *, -ve) = "" * StringUtils.mid("", 0, *) = "" * StringUtils.mid("abc", 0, 2) = "ab" * StringUtils.mid("abc", 0, 4) = "abc" * StringUtils.mid("abc", 2, 4) = "c" * StringUtils.mid("abc", 4, 2) = "" * StringUtils.mid("abc", -2, 2) = "ab" * </pre> * * @param str ? * @param pos ?? * @param len ? the length of the required String * @return ?, ?? null? <code>null</code> */ public static String mid(String str, int pos, int len) { return StringUtils.mid(str, pos, len); } /** * CRLF(newLine) ?? ?? ?? CRLF(?) SPACE .<br><br> * * StringUtils.newLineToSpace("\r\ntest") = " test" * * @param str * the String to convert * @return the converted string */ public static String newLineToSpace(String str) { String output; output = str.replace("\r\n", " "); return output; } /** * ? ?? ? ? ? .<br> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String normalizeSpace(String str) { return StringUtils.normalizeSpace(str); } // Mid //----------------------------------------------------------------------- /** * String ? null? "" ? , ?? .<br><br> * * StringUtils.nullToEmpty("test") = "test"<br> * StringUtils.nullToEmpty(null) = "" * * @param str * the String to check * @return empty string if the given String is null, given string if not */ public static String nullToEmpty(String str) { if (str == null || str.length() <= 0) { return DEFAULT_EMPTY_STRING; } else { return str; } } /** * Object null? ? Object , null? default Object .<br><br> * * StringUtils.nvl(null, "NULL TEST") = "NULL TEST"<br> * StringUtils.nvl("test", "NULL TEST") = "test" * * @param inputObject * the Object to check * @param defaultObject * the default Object * @return Returns the default Object if the given Object is null, returns * the given Object if not */ public static Object nvl(Object inputObject, Object defaultObject) { return inputObject != null ? inputObject : defaultObject; } /** * String? null? ? String? , null? default String? .<br><br> * * StringUtils.nvl(null, "NULL TEST") = "NULL TEST"<br> * StringUtils.nvl("test", "NULL TEST")) = "test" * * @param inputString * the String to check * @param defaultString * the default String * @return Returns the default String if the given String is null, returns * the given String if not */ public static String nvl(String inputString, String defaultString) { return (String) nvl((Object) inputString, (Object) defaultString); } /** * ? ? ?? n ?? .<br> * * <pre> * StringUtils.ordinalIndexOf(null, *, *) = -1 * StringUtils.ordinalIndexOf(*, null, *) = -1 * StringUtils.ordinalIndexOf("", "", *) = 0 * StringUtils.ordinalIndexOf("aabaabaa", "a", 1) = 0 * StringUtils.ordinalIndexOf("aabaabaa", "a", 2) = 1 * StringUtils.ordinalIndexOf("aabaabaa", "b", 1) = 2 * StringUtils.ordinalIndexOf("aabaabaa", "b", 2) = 5 * StringUtils.ordinalIndexOf("aabaabaa", "ab", 1) = 1 * StringUtils.ordinalIndexOf("aabaabaa", "ab", 2) = 4 * StringUtils.ordinalIndexOf("aabaabaa", "", 1) = 0 * StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0 * </pre> * * @param str ? * @param searchStr ? * @param ordinal n * @return ?? n ??-1 (INDEX_NOT_FOUND) ? ? null ? */ public static int ordinalIndexOf(String str, String searchStr, int ordinal) { return StringUtils.ordinalIndexOf(str, searchStr, ordinal); } /** * ?? ? ? ? .<br> * * <pre> * StringUtils.overlay(null, *, *, *) = null * StringUtils.overlay("", "abc", 0, 0) = "abc" * StringUtils.overlay("abcdef", null, 2, 4) = "abef" * StringUtils.overlay("abcdef", "", 2, 4) = "abef" * StringUtils.overlay("abcdef", "", 4, 2) = "abef" * StringUtils.overlay("abcdef", "zzzz", 2, 4) = "abzzzzef" * StringUtils.overlay("abcdef", "zzzz", 4, 2) = "abzzzzef" * StringUtils.overlay("abcdef", "zzzz", -1, 4) = "zzzzef" * StringUtils.overlay("abcdef", "zzzz", 2, 8) = "abzzzz" * StringUtils.overlay("abcdef", "zzzz", -2, -3) = "zzzzabcdef" * StringUtils.overlay("abcdef", "zzzz", 8, 10) = "abcdefzzzz" * </pre> * * @param str ? * @param overlay ? * @param start ? * @param end ? * @return ?, ?? null? <code>null</code> */ public static String overlay(String str, String overlay, int start, int end) { return StringUtils.overlay(str, overlay, start, end); } private static String padChar(String str, int size, char padChar, boolean isLeft) { if (str == null) { return null; } int originalStrLength = str.length(); if (size < originalStrLength) { return str; } int difference = size - originalStrLength; StringBuilder strBuf = new StringBuilder(); if (!isLeft) { strBuf.append(str); } for (int i = 0; i < difference; i++) { strBuf.append(padChar); } if (isLeft) { strBuf.append(str); } return strBuf.toString(); } // Mid //----------------------------------------------------------------------- /** * ?(char) ? ? ? ?? ? ? ?? ?.<br> * ? ? 0? ""? ? ? 0 null? .<br> * length String.getBytes().length ? String.length() ? ?.<br><br> * * StringUtils.padding(5, 'e') = "eeeee" * * @param size * the length to pad to * @param padChar * the character to pad with * @return padded String */ public static String padding(int size, char padChar) { if (size < 0) { return null; } StringBuffer buffer = new StringBuffer(size); for (int i = 0; i < size; i++) { buffer.insert(i, padChar); } return buffer.toString(); } // Mid //----------------------------------------------------------------------- private static String padString(String str, int size, String padStr, boolean isLeft) { if (str == null) { return null; } int originalStrLength = str.length(); if (size < originalStrLength) { return str; } int difference = size - originalStrLength; String tempPad = ""; if (difference > 0) { if (padStr == null || "".equals(padStr)) { padStr = " "; } do { for (int j = 0; j < padStr.length(); j++) { tempPad += padStr.charAt(j); if (str.length() + tempPad.length() >= size) { break; } } } while (difference > tempPad.length()); if (isLeft) { str = tempPad + str; } else { str = str + tempPad; } } return str; } // Mid //----------------------------------------------------------------------- /** * ? ? ? ?? ? .<br> * * <pre> * StringUtils.remove(null, *) = null * StringUtils.remove("", *) = "" * StringUtils.remove("queued", 'u') = "qeed" * StringUtils.remove("queued", 'z') = "queued" * </pre> * * @param str ? * @param remove ? * @return ?, ?? null? <code>null</code> */ public static String remove(String str, char remove) { return StringUtils.remove(str, remove); } /** * ? ? ?? ?? ? .<br> * * <pre> * StringUtils.remove(null, *) = null * StringUtils.remove("", *) = "" * StringUtils.remove(*, null) = * * StringUtils.remove(*, "") = * * StringUtils.remove("queued", "ue") = "qd" * StringUtils.remove("queued", "zz") = "queued" * </pre> * * @param str ? * @param remove ? * @return ?, ?? null? <code>null</code> */ public static String remove(String str, String remove) { return StringUtils.remove(str, remove); } /** * ? ?? ?? ? <br><br> * * StringUtils.removeAll("Anyframe Java Test", "Java") = "Anyfrme Test" * * @param str ? * @param charsToDelete ? * @return ?? ? * @see org.springframework.util.StringUtils#deleteAny(String, String) */ public static String removeAll(String str, String charsToDelete) { return org.springframework.util.StringUtils.deleteAny(str, charsToDelete); } /** * String ? ? ?(char) .<br><br> * * StringUtils.removeChar("ABBBBBC", 'B') = "AC" * * @param str * the source String to search * @param remove * the char to search for and remove * @return the substring with the char removed if found */ public static String removeChar(String str, char remove) { return replacePattern(str, String.valueOf(remove), ""); } // Mid //----------------------------------------------------------------------- /** * String ? ? ?? .<br> * ? ? ? . {'/', '-', ':', ',', '.', '%' }<br><br> * * StringUtils.removeCharAll("test/-") = "test" * * @param str * the source String to search * @return the substring with specified chars removed if found */ public static String removeCharAll(String str) { char[] targetCharacters = { '/', '-', ':', ',', '.', '%' }; return removeCharAll(str, targetCharacters); } /** * String ? ? ?? .<br><br> * * StringUtils.removeCharAll("AbbzzB", new char[]{'b','z'}) = "AB" * * @param str * the source String to search * @param remove * chars to search for (case insensitive) and remove * @return the substring with given chars removed if found */ public static String removeCharAll(String str, char[] remove) { String value = str; for (int i = 0; i < remove.length; i++) { value = removeChar(value, remove[i]); } return value; } /** * ?? ? ? ? ? .<br> * * <pre> * StringUtils.removeEnd(null, *) = null * StringUtils.removeEnd("", *) = "" * StringUtils.removeEnd(*, null) = * * StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com" * StringUtils.removeEnd("www.domain.com", ".com") = "www.domain" * StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com" * StringUtils.removeEnd("abc", "") = "abc" * </pre> * * @param str ? * @param remove ? * @return ?, ?? null? <code>null</code> */ public static String removeEnd(String str, String remove) { return StringUtils.removeEnd(str, remove); } /** * ?? ? ? ?? ? ? ? .<br> * * <pre> * StringUtils.removeEndIgnoreCase(null, *) = null * StringUtils.removeEndIgnoreCase("", *) = "" * StringUtils.removeEndIgnoreCase(*, null) = * * StringUtils.removeEndIgnoreCase("www.domain.com", ".com.") = "www.domain.com" * StringUtils.removeEndIgnoreCase("www.domain.com", ".com") = "www.domain" * StringUtils.removeEndIgnoreCase("www.domain.com", "domain") = "www.domain.com" * StringUtils.removeEndIgnoreCase("abc", "") = "abc" * StringUtils.removeEndIgnoreCase("www.domain.com", ".COM") = "www.domain") * StringUtils.removeEndIgnoreCase("www.domain.COM", ".com") = "www.domain") * </pre> * * @param str ? * @param remove ? * @return ?, ?? null? <code>null</code> */ public static String removeEndIgnoreCase(String str, String remove) { return StringUtils.removeEndIgnoreCase(str, remove); } /** * ?? ?? ?? .<br> * * <pre> * StringUtils.removeStart(null, *) = null * StringUtils.removeStart("", *) = "" * StringUtils.removeStart(*, null) = * * StringUtils.removeStart("www.domain.com", "www.") = "domain.com" * StringUtils.removeStart("domain.com", "www.") = "domain.com" * StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com" * StringUtils.removeStart("abc", "") = "abc" * </pre> * * @param str ? * @param remove ? * @return ?, ?? null? <code>null</code> */ public static String removeStart(String str, String remove) { return StringUtils.removeStart(str, remove); } /** * ?? ? ?? ? ? ? .<br> * * <pre> * StringUtils.removeStartIgnoreCase(null, *) = null * StringUtils.removeStartIgnoreCase("", *) = "" * StringUtils.removeStartIgnoreCase(*, null) = * * StringUtils.removeStartIgnoreCase("www.domain.com", "www.") = "domain.com" * StringUtils.removeStartIgnoreCase("www.domain.com", "WWW.") = "domain.com" * StringUtils.removeStartIgnoreCase("domain.com", "www.") = "domain.com" * StringUtils.removeStartIgnoreCase("www.domain.com", "domain") = "www.domain.com" * StringUtils.removeStartIgnoreCase("abc", "") = "abc" * </pre> * * @param str ? * @param remove ? * @return ?, ?? null? <code>null</code> */ public static String removeStartIgnoreCase(String str, String remove) { return StringUtils.removeStartIgnoreCase(str, remove); } /** * ?? ? <br><br> * * StringUtils.removeWhitespace("Anyframe Java Test") = "AnyframeJavaTest" * * @param str ? * @return ? ? * @see org.springframework.util.StringUtils#trimAllWhitespace(String) */ public static String removeWhitespace(String str) { return org.springframework.util.StringUtils.trimAllWhitespace(str); } /** * ?? ? .<br> * * <pre> * StringUtils.repeat(null, 2) = null * StringUtils.repeat("", 0) = "" * StringUtils.repeat("", 2) = "" * StringUtils.repeat("a", 3) = "aaa" * StringUtils.repeat("ab", 2) = "abab" * StringUtils.repeat("a", -2) = "" * </pre> * * @param str ? * @param repeat * @return ?, ?? null? <code>null</code> */ public static String repeat(String str, int repeat) { return StringUtils.repeat(str, repeat); } /** * ? ? ? .<br> * * <pre> * StringUtils.repeat(null, null, 2) = null * StringUtils.repeat(null, "x", 2) = null * StringUtils.repeat("", null, 0) = "" * StringUtils.repeat("", "", 2) = "" * StringUtils.repeat("", "x", 3) = "xx" * StringUtils.repeat("?", ", ", 3) = "?, ?, ?" * </pre> * * @param str ? * @param separator ? * @param repeat * @return ?, ?? null? <code>null</code> */ public static String repeat(String str, String separator, int repeat) { return StringUtils.repeat(str, separator, repeat); } /** * ? ?? character ? <br><br> * * StringUtils.replace("Anyframe/Common", "/", "|") = "Anyframe|Common" * * @param str ? * @param replacedStr ? * @param replaceStr ? * @return ? ?? ? */ public static String replace(String str, String replacedStr, String replaceStr) { String newStr = ""; if (str.indexOf(replacedStr) != -1) { String s1 = str.substring(0, str.indexOf(replacedStr)); String s2 = str.substring(str.indexOf(replacedStr) + replacedStr.length()); newStr = s1 + replaceStr + s2; } return newStr; } /** * ? ? ?? ? ? .<br> * * <pre> * StringUtils.replace(null, *, *, *) = null * StringUtils.replace("", *, *, *) = "" * StringUtils.replace("any", null, *, *) = "any" * StringUtils.replace("any", *, null, *) = "any" * StringUtils.replace("any", "", *, *) = "any" * StringUtils.replace("any", *, *, 0) = "any" * StringUtils.replace("abaa", "a", null, -1) = "abaa" * StringUtils.replace("abaa", "a", "", -1) = "b" * StringUtils.replace("abaa", "a", "z", 0) = "abaa" * StringUtils.replace("abaa", "a", "z", 1) = "zbaa" * StringUtils.replace("abaa", "a", "z", 2) = "zbza" * StringUtils.replace("abaa", "a", "z", -1) = "zbzz" * </pre> * * @param text ? * @param searchString ? * @param replacement ? * @param max * @return ?, ?? null? <code>null</code> */ public static String replace(String text, String searchString, String replacement, int max) { return StringUtils.replace(text, searchString, replacement, max); } /** * ? ?? ? ? ?? ? <br><br> * * StringUtils.replaceAll("Anyframe Java Test Anyframe Java Test", "Anyframe", "Enterprise") = "Enterprise Java Test Enterprise Java Test" * * @param source ? * @param regex ? * @param replacement ? * @return ? ?? ? * @see String#replaceAll(String, String) */ public static String replaceAll(String source, String regex, String replacement) { if (source == null) { return null; } return source.replaceAll(regex, replacement); } // Replace, character based //----------------------------------------------------------------------- /** * ?? ? ? ? .<br> * * <pre> * StringUtils.replaceChars(null, *, *) = null * StringUtils.replaceChars("", *, *) = "" * StringUtils.replaceChars("abcba", 'b', 'y') = "aycya" * StringUtils.replaceChars("abcba", 'z', 'y') = "abcba" * </pre> * * @param str ? * @param searchChar ? * @param replaceChar ? * @return ?, ?? null? <code>null</code> */ public static String replaceChars(String str, char searchChar, char replaceChar) { return StringUtils.replaceChars(str, searchChar, replaceChar); } /** * ?? ? ? ? .<br> * * <pre> * StringUtils.replaceChars(null, *, *) = null * StringUtils.replaceChars("", *, *) = "" * StringUtils.replaceChars("abc", null, *) = "abc" * StringUtils.replaceChars("abc", "", *) = "abc" * StringUtils.replaceChars("abc", "b", null) = "ac" * StringUtils.replaceChars("abc", "b", "") = "ac" * StringUtils.replaceChars("abcba", "bc", "yz") = "ayzya" * StringUtils.replaceChars("abcba", "bc", "y") = "ayya" * StringUtils.replaceChars("abcba", "bc", "yzx") = "ayzya" * </pre> * * @param str ? * @param searchChars ? * @param replaceChars ? * @return ?, ?? null? <code>null</code> */ public static String replaceChars(String str, String searchChars, String replaceChars) { return StringUtils.replaceChars(str, searchChars, replaceChars); } /** * ?? ? ? ?? ? ??? ? .<br> * * <pre> * StringUtils.replaceEach(null, *, *) = null * StringUtils.replaceEach("", *, *) = "" * StringUtils.replaceEach("aba", null, null) = "aba" * StringUtils.replaceEach("aba", new String[0], null) = "aba" * StringUtils.replaceEach("aba", null, new String[0]) = "aba" * StringUtils.replaceEach("aba", new String[]{"a"}, null) = "aba" * StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""}) = "b" * StringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"}) = "aba" * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}) = "wcte" * (example of how it does not repeat) * StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}) = "dcte" * </pre> * * @param text ? * @param searchList * @param replacementList * @return ?, ?? null? <code>null</code> */ public static String replaceEach(String text, String[] searchList, String[] replacementList) { return StringUtils.replaceEach(text, searchList, replacementList); } /** * ?? ? ? ?? ? ??? ? ?<br> * ? ?? .<br> * * <pre> * StringUtils.replaceEachRepeatedly(null, *, *) = null * StringUtils.replaceEachRepeatedly("", *, *) = "" * StringUtils.replaceEachRepeatedly("aba", null, null) = "aba" * StringUtils.replaceEachRepeatedly("aba", new String[0], null) = "aba" * StringUtils.replaceEachRepeatedly("aba", null, new String[0]) = "aba" * StringUtils.replaceEachRepeatedly("aba", new String[]{"a"}, null) = "aba" * StringUtils.replaceEachRepeatedly("aba", new String[]{"a"}, new String[]{""}) = "b" * StringUtils.replaceEachRepeatedly("aba", new String[]{null}, new String[]{"a"}) = "aba" * StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"}) = "wcte" * StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"}) = "tcte" * StringUtils.replaceEachRepeatedly("abcde", new String[]{"ab", "d"}, new String[]{"d", "ab"}) = IllegalArgumentException * </pre> * * @param text ? * @param searchList * @param replacementList * @return ?, ?? null? <code>null</code> */ public static String replaceEachRepeatedly(String text, String[] searchList, String[] replacementList) { return StringUtils.replaceEachRepeatedly(text, searchList, replacementList); } /** * ? ?? ? ? ?? ? <br><br> * * StringUtils.replaceFirst("Anyframe Java Test Anyframe Java Test", "Anyframe", "Enterprise") = "Enterprise Java Test Anyframe Java Test" * * @param source ? * @param regex ? * @param replacement ? * @return ? ? ?? ? * @see String#replaceFirst(String, String) */ public static String replaceFirst(String source, String regex, String replacement) { if (source == null) { return null; } return source.replaceFirst(regex, replacement); } /** * ? ?? ? ? ?? ? <br><br> * * StringUtils.replaceLast("Anyframe Java Test Anyframe Java Test", "Anyframe", "Enterprise") = "Anyframe Java Test Enterprise Java Test" * * @param source ? * @param regex ? * @param replacement ? * @return ? ? ?? ? */ public static String replaceLast(String source, String regex, String replacement) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(source); if (!matcher.find()) { return source; } int lastMatchStart = 0; do { lastMatchStart = matcher.start(); } while (matcher.find()); matcher.find(lastMatchStart); StringBuffer sb = new StringBuffer(source.length()); matcher.appendReplacement(sb, replacement); matcher.appendTail(sb); return sb.toString(); } // Mid //----------------------------------------------------------------------- /** * ? ? ?? ? .<br> * * <pre> * StringUtils.replaceOnce(null, *, *) = null * StringUtils.replaceOnce("", *, *) = "" * StringUtils.replaceOnce("any", null, *) = "any" * StringUtils.replaceOnce("any", *, null) = "any" * StringUtils.replaceOnce("any", "", *) = "any" * StringUtils.replaceOnce("aba", "a", null) = "aba" * StringUtils.replaceOnce("aba", "a", "") = "ba" * StringUtils.replaceOnce("aba", "a", "z") = "zba" * </pre> * * @param text ? * @param searchString ? * @param replacement ? * @return ?, ?? null? <code>null</code> */ public static String replaceOnce(String text, String searchString, String replacement) { return StringUtils.replaceOnce(text, searchString, replacement); } /** * String ? ? (old)? (new) .<br> * ? ? .<br> * ?, ? ?? old ? ? .<br><br> * * StringUtils.replacePattern("abaa", "aba", "bab") = "baba" * * @param text * text to search and replace in, may be null * @param searchString * the String to search for, may be null * @param replacement * the String to replace it with, may be null * @return the text with any replacements processed, null if null String * input */ public static String replacePattern(String text, String searchString, String replacement) { if (text == null) { return null; } if (searchString == null || replacement == null) { return text; } StringBuffer sbuf = new StringBuffer(); int pos = 0; int index = text.indexOf(searchString); int patLen = searchString.length(); for (; index >= 0; index = text.indexOf(searchString, pos)) { sbuf.append(text.substring(pos, index)); sbuf.append(replacement); pos = index + patLen; } sbuf.append(text.substring(pos)); return sbuf.toString(); } // Mid //----------------------------------------------------------------------- /** * ? ?? <br><br> * * StringUtils.reverse("Anyframe Java Test") = "tseT avaJ emarfynA" * * @param str ? * @return ? ? */ public static String reverse(String str) { if (str == null) { return null; } return new StringBuilder(str).reverse().toString(); } /** * ? ?? ? .<br> * * <pre> * StringUtils.reverseDelimited(null, *) = null * StringUtils.reverseDelimited("", *) = "" * StringUtils.reverseDelimited("a.b.c", 'x') = "a.b.c" * StringUtils.reverseDelimited("a.b.c", ".") = "c.b.a" * </pre> * * @param str ? * @param separatorChar ? * @return ?, ?? null? <code>null</code> */ public static String reverseDelimited(String str, char separatorChar) { return StringUtils.reverseDelimited(str, separatorChar); } // Mid //----------------------------------------------------------------------- /** * String ?? ?? ? .<br> * ? String? ? ? ? String? .<br> * "..."? ? ?? splitTail() ??.<br><br> * * StringUtils.right("1234567", 3) = "567" * * @param str * the String to get the rightmost characters from, may be null * @param len * the length of the required String * @return the rightmost characters, null if null String input */ public static String right(String str, int len) { if (str == null) { return null; } else if (len <= 0 || str.length() <= len) { return str; } else { return str.substring(str.length() - len); } } /** * ?? ? ?? ? .<br><br> * * StringUtils.rightPad("Anyframe", 12) = "Anyframe " * * @param str ? * @param size ? ?? ? * @return ?? ? ? */ public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } /** * ?? ? ?? ? ? ? .<br><br> * * StringUtils.rightPad("Anyframe", 12, 'a') = "Anyframeaaaa" * * @param str ? * @param size ? ?? ? * @param padChar ? ? * @return ?? ? ? */ public static String rightPad(String str, int size, char padChar) { return padChar(str, size, padChar, false); } /** * ?? ? ?? ? ? ? .<br><br> * * StringUtils.rightPad("Anyframe", 12, "Java") = "AnyframeJava" * * @param str ? * @param size ?? ?? ? * @param padStr ? ? * @return ?? ?? ? */ public static String rightPad(String str, int size, String padStr) { return padString(str, size, padStr, false); } /** * ?? ? ? <br><br> * * StringUtils.rightTrim("Anyframe Java Test ") = "Anyframe Java Test" * * @param str ? * @return ? ? * @see org.springframework.util.StringUtils#trimTrailingWhitespace(String) */ public static String rightTrim(String str) { return org.springframework.util.StringUtils.trimTrailingWhitespace(str); } /** * ? ? ?? .<br> * * <pre> * StringUtils.split(null) = null * StringUtils.split("") = [] * StringUtils.split("abc def") = ["abc", "def"] * StringUtils.split("abc def") = ["abc", "def"] * StringUtils.split(" abc ") = ["abc"] * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String[] split(String str) { return StringUtils.split(str); } /** * String? separator(char) ? tokenize String[] .<br> * ?? separator ? token? ? .<br> * String? null? , null? return.<br><br> * * StringUtils.split("aaVbbVcc", 'V') = {"aa", "bb", "cc"} * * @param str * the String to parse * @param separator * the character used as the delimiter * @return an array of parsed Strings */ public static String[] split(String str, char separator) { StringBuffer tempStringBuffer = new StringBuffer(); tempStringBuffer.append(separator); return tokenizeToStringArray(str, tempStringBuffer.toString(), false); } /** * ?? ? .<br> * * <pre> * StringUtils.split(null, *) = null * StringUtils.split("", *) = [] * StringUtils.split("abc def", null) = ["abc", "def"] * StringUtils.split("abc def", " ") = ["abc", "def"] * StringUtils.split("abc def", " ") = ["abc", "def"] * StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"] * </pre> * * @param str ? * @param separatorChars ? * @return ?, ?? null? <code>null</code> */ public static String[] split(String str, String separatorChars) { return StringUtils.split(str, separatorChars); } // Mid //----------------------------------------------------------------------- /** * ?? ? ? ?? .<br> * * <pre> * StringUtils.split(null, *, *) = null * StringUtils.split("", *, *) = [] * StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"] * StringUtils.split("ab de fg", null, 0) = ["ab", "cd", "ef"] * StringUtils.split("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"] * StringUtils.split("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] * </pre> * * @param str ? * @param separatorChars ? * @param max ? * @return ?, ?? null? <code>null</code> */ public static String[] split(String str, String separatorChars, int max) { return StringUtils.split(str, separatorChars, max); } /** * ?? <code>java.lang.Character.getType(char)</code>? <br> * .??<br> * * <pre> * StringUtils.splitByCharacterType(null) = null * StringUtils.splitByCharacterType("") = [] * StringUtils.splitByCharacterType("ab de fg") = ["ab", " ", "de", " ", "fg"] * StringUtils.splitByCharacterType("ab de fg") = ["ab", " ", "de", " ", "fg"] * StringUtils.splitByCharacterType("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"] * StringUtils.splitByCharacterType("number5") = ["number", "5"] * StringUtils.splitByCharacterType("fooBar") = ["foo", "B", "ar"] * StringUtils.splitByCharacterType("foo200Bar") = ["foo", "200", "B", "ar"] * StringUtils.splitByCharacterType("ASFRules") = ["ASFR", "ules"] * </pre> * @param str ? * @return ?, ?? null? <code>null</code> */ public static String[] splitByCharacterType(String str) { return StringUtils.splitByCharacterType(str); } // Mid //----------------------------------------------------------------------- /** * ?? <code>java.lang.Character.getType(char)</code>? <br> * .???<br> * * <pre> * StringUtils.splitByCharacterTypeCamelCase(null) = null * StringUtils.splitByCharacterTypeCamelCase("") = [] * StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"] * StringUtils.splitByCharacterTypeCamelCase("ab de fg") = ["ab", " ", "de", " ", "fg"] * StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef") = ["ab", ":", "cd", ":", "ef"] * StringUtils.splitByCharacterTypeCamelCase("number5") = ["number", "5"] * StringUtils.splitByCharacterTypeCamelCase("fooBar") = ["foo", "Bar"] * StringUtils.splitByCharacterTypeCamelCase("foo200Bar") = ["foo", "200", "Bar"] * StringUtils.splitByCharacterTypeCamelCase("ASFRules") = ["ASF", "Rules"] * </pre> * @param str ? * @return ?, ?? null? <code>null</code> */ public static String[] splitByCharacterTypeCamelCase(String str) { return StringUtils.splitByCharacterTypeCamelCase(str); } /** * ?? ? .<br> * * <pre> * StringUtils.splitByWholeSeparator(null, *) = null * StringUtils.splitByWholeSeparator("", *) = [] * StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"] * StringUtils.splitByWholeSeparator("ab de fg", null) = ["ab", "de", "fg"] * StringUtils.splitByWholeSeparator("ab:cd:ef", ":") = ["ab", "cd", "ef"] * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"] * </pre> * * @param str ? * @param separator ? * @return ?, ?? null? <code>null</code> */ public static String[] splitByWholeSeparator(String str, String separator) { return StringUtils.splitByWholeSeparator(str, separator); } /** * ?? ? ? ?? .<br> * * <pre> * StringUtils.splitByWholeSeparator(null, *, *) = null * StringUtils.splitByWholeSeparator("", *, *) = [] * StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"] * StringUtils.splitByWholeSeparator("ab de fg", null, 0) = ["ab", "de", "fg"] * StringUtils.splitByWholeSeparator("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"] * StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"] * </pre> * * @param str ? * @param separator ? * @param max ? * @return ?, ?? null? <code>null</code> */ public static String[] splitByWholeSeparator(String str, String separator, int max) { return StringUtils.splitByWholeSeparator(str, separator, max); } /** * ?? ? .<br> * * <pre> * StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *) = null * StringUtils.splitByWholeSeparatorPreserveAllTokens("", *) = [] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "de", "fg"] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "", "", "de", "fg"] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"] * </pre> * * @param str ? * @param separator ? * @return ?, ?? null? <code>null</code> */ public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator) { return StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separator); } /** * ?? ? ? ?? .<br> * * <pre> * StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *, *) = null * StringUtils.splitByWholeSeparatorPreserveAllTokens("", *, *) = [] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "de", "fg"] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 0) = ["ab", "", "", "de", "fg"] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 5) = ["ab", "cd", "ef"] * StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-", 2) = ["ab", "cd-!-ef"] * </pre> * * @param str ? * @param separator ? * @param max ? * @return ?, ?? null? <code>null</code> */ public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator, int max) { return StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separator, max); } /** * ?? ? ? ? ?.<br><br> * * StringUtils.splitHead("Anyframe Java Test", 3) = "Any" * * @param str ? * @param size ?? ? ? * @return ?? ? ? ? */ public static String splitHead(String str, int size) { if (str == null) { return ""; } if (str.length() > size) { str = str.substring(0, size); } return str; } /** * String ?? ?? ? .<br> * ? String? ? ? ? String? .<br> * ? ? "..."? .<br><br> * * StringUtils.splitHead("12345678", 3) = "123..." * * @param str * the String to get the leftmost characters from, may be null * @param len * the length of the required String * @return the leftmost characters with ellipsis, null if null String input */ public static String splitHeadWithEllipsis(String str, int len) { if (str == null) { return null; } else if (len <= 0 || str.length() <= len) { return str; } else { return str.substring(0, len) + "..."; } } /** * ? ? ?? .<br> * * <pre> * StringUtils.splitPreserveAllTokens(null) = null * StringUtils.splitPreserveAllTokens("") = [] * StringUtils.splitPreserveAllTokens("abc def") = ["abc", "def"] * StringUtils.splitPreserveAllTokens("abc def") = ["abc", "", "def"] * StringUtils.splitPreserveAllTokens(" abc ") = ["", "abc", ""] * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String[] splitPreserveAllTokens(String str) { return StringUtils.splitPreserveAllTokens(str); } /** * ?? ? .<br> * * <pre> * StringUtils.splitPreserveAllTokens(null, *) = null * StringUtils.splitPreserveAllTokens("", *) = [] * StringUtils.splitPreserveAllTokens("a.b.c", '.') = ["a", "b", "c"] * StringUtils.splitPreserveAllTokens("a..b.c", '.') = ["a", "", "b", "c"] * StringUtils.splitPreserveAllTokens("a:b:c", '.') = ["a:b:c"] * StringUtils.splitPreserveAllTokens("a\tb\nc", null) = ["a", "b", "c"] * StringUtils.splitPreserveAllTokens("a b c", ' ') = ["a", "b", "c"] * StringUtils.splitPreserveAllTokens("a b c ", ' ') = ["a", "b", "c", ""] * StringUtils.splitPreserveAllTokens("a b c ", ' ') = ["a", "b", "c", "", ""] * StringUtils.splitPreserveAllTokens(" a b c", ' ') = ["", a", "b", "c"] * StringUtils.splitPreserveAllTokens(" a b c", ' ') = ["", "", a", "b", "c"] * StringUtils.splitPreserveAllTokens(" a b c ", ' ') = ["", a", "b", "c", ""] * </pre> * * @param str ? * @param separatorChar ? * @return ?, ?? null? <code>null</code> */ public static String[] splitPreserveAllTokens(String str, char separatorChar) { return StringUtils.splitPreserveAllTokens(str, separatorChar); } /** * ?? ? .<br> * * <pre> * StringUtils.splitPreserveAllTokens(null, *) = null * StringUtils.splitPreserveAllTokens("", *) = [] * StringUtils.splitPreserveAllTokens("abc def", null) = ["abc", "def"] * StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "def"] * StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "", def"] * StringUtils.splitPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"] * StringUtils.splitPreserveAllTokens("ab:cd:ef:", ":") = ["ab", "cd", "ef", ""] * StringUtils.splitPreserveAllTokens("ab:cd:ef::", ":") = ["ab", "cd", "ef", "", ""] * StringUtils.splitPreserveAllTokens("ab::cd:ef", ":") = ["ab", "", cd", "ef"] * StringUtils.splitPreserveAllTokens(":cd:ef", ":") = ["", cd", "ef"] * StringUtils.splitPreserveAllTokens("::cd:ef", ":") = ["", "", cd", "ef"] * StringUtils.splitPreserveAllTokens(":cd:ef:", ":") = ["", cd", "ef", ""] * </pre> * * @param str ? * @param separatorChars ? * @return ?, ?? null? <code>null</code> */ public static String[] splitPreserveAllTokens(String str, String separatorChars) { return StringUtils.splitPreserveAllTokens(str, separatorChars); } /** * ?? ? ? ?? .<br> * * <pre> * StringUtils.splitPreserveAllTokens(null, *, *) = null * StringUtils.splitPreserveAllTokens("", *, *) = [] * StringUtils.splitPreserveAllTokens("ab cd ef", null, 0) = ["ab", "cd", "ef"] * StringUtils.splitPreserveAllTokens("ab cd ef", null, 0) = [ab, , , cd, ef] * StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 0) = ["ab", "cd", "ef"] * StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 2) = ["ab", "cd:ef"] * StringUtils.splitPreserveAllTokens("ab de fg", null, 2) = ["ab", " de fg"] * StringUtils.splitPreserveAllTokens("ab de fg", null, 3) = ["ab", "", " de fg"] * StringUtils.splitPreserveAllTokens("ab de fg", null, 4) = ["ab", "", "", "de fg"] * </pre> * * @param str ? * @param separatorChars ? * @param max ? * @return ?, ?? null? <code>null</code> */ public static String[] splitPreserveAllTokens(String str, String separatorChars, int max) { return StringUtils.splitPreserveAllTokens(str, separatorChars, max); } /** * ?? ? ? ? ?.<br><br> * * StringUtils.splitTail("Anyframe Java Test", 3) = "est" * * @param str ? * @param size ?? ? ? * @return ?? ? ? ? */ public static String splitTail(String str, int size) { if (str == null) { return ""; } if (str.length() > size) { str = str.substring(str.length() - size); } return str; } // Mid //----------------------------------------------------------------------- /** * String ?? ?? ? .<br> * ? String? ? ? ? String? .<br> * ? ? "..."? .<br><br> * * StringUtils.splitTail("12345678", 3) = "...678" * * @param str * the String to get the rightmost characters from, may be null * @param len * the length of the required String * @return the rightmost characters with ellipsis, null if null String input */ public static String splitTailWithEllipsis(String str, int len) { if (str == null) { return null; } else if (len <= 0 || str.length() <= len) { return str; } else { return "..." + str.substring(str.length() - len); } } /** * ?? ? ? ?.<br> * * <pre> * StringUtils.startsWith(null, null) = true * StringUtils.startsWith(null, "abc") = false * StringUtils.startsWith("abcdef", null) = false * StringUtils.startsWith("abcdef", "abc") = true * StringUtils.startsWith("ABCDEF", "abc") = false * </pre> * * @param str ? * @param prefix ? * @return ?? ? ? ? ? <code>null</code>? <code>true</code> */ public static boolean startsWith(String str, String prefix) { return StringUtils.startsWith(str, prefix); } /** * ?? ? ? ? ?.<br> * * <pre> * StringUtils.startsWithAny(null, null) = false * StringUtils.startsWithAny(null, new String[] {"abc"}) = false * StringUtils.startsWithAny("abcxyz", null) = false * StringUtils.startsWithAny("abcxyz", new String[] {""}) = true * StringUtils.startsWithAny("abcxyz", new String[] {"abc"}) = true * StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true * </pre> * * @param string ? * @param searchStrings ? * @return ?? ? ? ? ? ? * <code>null</code>? <code>true</code> */ public static boolean startsWithAny(String string, String[] searchStrings) { return StringUtils.startsWithAny(string, searchStrings); } /** * ?? ? ? ? ? ?.<br> * * <pre> * StringUtils.startsWithIgnoreCase(null, null) = true * StringUtils.startsWithIgnoreCase(null, "abc") = false * StringUtils.startsWithIgnoreCase("abcdef", null) = false * StringUtils.startsWithIgnoreCase("abcdef", "abc") = true * StringUtils.startsWithIgnoreCase("ABCDEF", "abc") = true * </pre> * * @param str ? * @param prefix ? * @return ?? ? ? ? ? ? ? * <code>null</code>? <code>true</code> */ public static boolean startsWithIgnoreCase(String str, String prefix) { return StringUtils.startsWithIgnoreCase(str, prefix); } /** * ?? ? .<br><br> * * StringUtils.string2integer("14") = 14 * * @param str * string representation of a number * @return integer integer type of string */ public static int string2integer(String str) { int ret = Integer.parseInt(str.trim()); return ret; } /** * ?? BigDecimal .<br><br> * * StringUtils.stringToBigDecimal("14") = 14 * * @param str * the String value to convert * @return the converted BigDecimal */ public static BigDecimal stringToBigDecimal(String str) { if ("".equals(rightTrim(str))) { return new BigDecimal(0); } else { return new BigDecimal(str); } } /** * ?? ? ? ?? BigDecimal .<br><br> * * StringUtils.stringToBigDecimal("123456", 0, 2) = 12 * * @param str ? * @param pos * @param len ? * @return ? BigDecimal */ public static BigDecimal stringToBigDecimal(String str, int pos, int len) { if ("".equals(rightTrim(str))) { return new BigDecimal(0); } else if (str.length() < pos + len) { return stringToBigDecimal(leftPad(str, pos + len, "0")); } else { return stringToBigDecimal(str.substring(pos, pos + len)); } } /** * ?? hex . ()<br><br> * * StringUtils.stringToHex("123") = "003100320033" * * @param str ? * @return ? hex ? */ public static String stringToHex(String str) { String inStr = str; char[] inChar = inStr.toCharArray(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < inChar.length; i++) { String hex = Integer.toHexString((int) inChar[i]); if (hex.length() == 2) { hex = "00" + hex; } sb.append(hex); } return sb.toString(); } /** * ?? .<br><br> * * StringUtils.stringToNumn("123") = 123 * * @param str ? * @return ? */ public static int stringToNumn(String str) { if ("".equals(rightTrim(str))) { return 0; } else { return Integer.parseInt(str); } } /** * ?? ? ? ?? .<br><br> * * StringUtils.stringToNumn("123456789", 5, 3) = 678 * * @param str ? * @param pos * @param len ? * @return ?? ? ? */ public static int stringToNumn(String str, int pos, int len) { if ("".equals(rightTrim(str))) { return 0; } else if (str.length() < pos + len) { return stringToNumn(leftPad(str, pos + len, "0")); } else { return stringToNumn(str.substring(pos, pos + len)); } } /** * ?? ??? ?? .<br> * * <pre> * StringUtils.strip(null) = null * StringUtils.strip("") = "" * StringUtils.strip(" ") = "" * StringUtils.strip("abc") = "abc" * StringUtils.strip(" abc") = "abc" * StringUtils.strip("abc ") = "abc" * StringUtils.strip(" abc ") = "abc" * StringUtils.strip(" ab c ") = "ab c" * </pre> * * @param str ? * @return null ? ? null * "" ? "" */ public static String strip(String str) { return StringUtils.strip(str); } /** * ? ? stripChars? ? .<br> * * <pre> * StringUtils.strip(null, *) = null * StringUtils.strip("", *) = "" * StringUtils.strip("abc", null) = "abc" * StringUtils.strip(" abc", null) = "abc" * StringUtils.strip("abc ", null) = "abc" * StringUtils.strip(" abc ", null) = "abc" * StringUtils.strip(" abcyx", "xyz") = " abc" * </pre> * * @param str ? * @param stripChars ? * @return null ? ? null * "" ? "" */ public static String strip(String str, String stripChars) { return StringUtils.strip(str, stripChars); } /** * ? ?? ? ? .<br> * * <pre> * StringUtils.stripAll(null) = null * StringUtils.stripAll([]) = [] * StringUtils.stripAll(["abc", " abc"]) = ["abc", "abc"] * StringUtils.stripAll(["abc ", null]) = ["abc", null] * </pre> * * @param strs ? * @return strip ? */ public static String[] stripAll(String[] strs) { return StringUtils.stripAll(strs); } // Mid //----------------------------------------------------------------------- /** * ? ?? ? ? ?? .<br> * * <pre> * StringUtils.stripAll(null, *) = null * StringUtils.stripAll([], *) = [] * StringUtils.stripAll(["abc", " abc"], null) = ["abc", "abc"] * StringUtils.stripAll(["abc ", null], null) = ["abc", null] * StringUtils.stripAll(["abc ", null], "yz") = ["abc ", null] * StringUtils.stripAll(["yabcz", null], "yz") = ["abc", null] * </pre> * * @param strs ? * @param stripChars ? * @return strip ? */ public static String[] stripAll(String[] strs, String stripChars) { return StringUtils.stripAll(strs, stripChars); } /** * ?? ? ? ? .<br> * * <pre> * StringUtils.stripEnd(null, *) = null * StringUtils.stripEnd("", *) = "" * StringUtils.stripEnd("abc", "") = "abc" * StringUtils.stripEnd("abc", null) = "abc" * StringUtils.stripEnd(" abc", null) = " abc" * StringUtils.stripEnd("abc ", null) = "abc" * StringUtils.stripEnd(" abc ", null) = " abc" * StringUtils.stripEnd(" abcyx", "xyz") = " abc" * StringUtils.stripEnd("120.00", ".0") = "12" * </pre> * * @param str ? * @param stripChars ? * @return null ? ? null * "" ? "" */ public static String stripEnd(String str, String stripChars) { return StringUtils.stripEnd(str, stripChars); } /** * ?? ? ? ? .<br> * * <pre> * StringUtils.stripStart(null, *) = null * StringUtils.stripStart("", *) = "" * StringUtils.stripStart("abc", "") = "abc" * StringUtils.stripStart("abc", null) = "abc" * StringUtils.stripStart(" abc", null) = "abc" * StringUtils.stripStart("abc ", null) = "abc " * StringUtils.stripStart(" abc ", null) = "abc " * StringUtils.stripStart("yxabc ", "xyz") = "abc " * </pre> * * @param str ? * @param stripChars ? * @return null ? ? null * "" ? "" */ public static String stripStart(String str, String stripChars) { return StringUtils.stripStart(str, stripChars); } /** * ? NULL? ? , ? ? <br> * ? .<br> * * <pre> * StringUtils.stripToEmpty(null) = "" * StringUtils.stripToEmpty("") = "" * StringUtils.stripToEmpty(" ") = "" * StringUtils.stripToEmpty("abc") = "abc" * StringUtils.stripToEmpty(" abc") = "abc" * StringUtils.stripToEmpty("abc ") = "abc" * StringUtils.stripToEmpty(" abc ") = "abc" * StringUtils.stripToEmpty(" ab c ") = "ab c" * </pre> * * @param str ? * @return null ? ? "" ? "" */ public static String stripToEmpty(String str) { return StringUtils.stripToEmpty(str); } /** * ? ? ? .<br> * * <pre> * StringUtils.stripToNull(null) = null * StringUtils.stripToNull("") = null * StringUtils.stripToNull(" ") = null * StringUtils.stripToNull("abc") = "abc" * StringUtils.stripToNull(" abc") = "abc" * StringUtils.stripToNull("abc ") = "abc" * StringUtils.stripToNull(" abc ") = "abc" * StringUtils.stripToNull(" ab c ") = "ab c" * </pre> * * @param str ? * @return null ? ? "" ? null */ public static String stripToNull(String str) { return StringUtils.stripToNull(str); } /** * ? ? ?? ?.<br> * * <p> * ?? ?? <code>n</code>? ? ?? ?. * </p> * * <p> * ?? <code>null</code>? <code>null</code>? . * ?? ? ? . * </p> * * <pre> * StringUtils.substring(null, *) = null * StringUtils.substring("", *) = "" * StringUtils.substring("abc", 0) = "abc" * StringUtils.substring("abc", 2) = "c" * StringUtils.substring("abc", 4) = " * " * StringUtils.substring("abc", -2) = "bc" * StringUtils.substring("abc", -4) = "abc" * </pre> * * @param str ? * @param start ? * @return ?? ?, ?? null? <code>null</code> */ public static String substring(String str, int start) { return StringUtils.substring(str, start); } /** * ? ? ?? ?.<br> * * <p> * ?? ?? <code>n</code>? ? ?? ?. * </p> * * <p> * ?? <code>null</code>? <code>null</code>? . * ?? ? ? . * </p> * * <pre> * StringUtils.substring(null, *, *) = null * StringUtils.substring("", * , *) = ""; * StringUtils.substring("abc", 0, 2) = "ab" * StringUtils.substring("abc", 2, 0) = "" * StringUtils.substring("abc", 2, 4) = "c" * StringUtils.substring("abc", 4, 6) = "" * StringUtils.substring("abc", 2, 2) = "" * StringUtils.substring("abc", -2, -1) = "b" * StringUtils.substring("abc", -4, 2) = "ab" * </pre> * * @param str ? * @param start ? * @param end ? * @return ? ?? ?, ?? null? <code>null</code> */ public static String substring(String str, int start, int end) { return StringUtils.substring(str, start, end); } /** * ?? ? SEPARATOR ?? .<br> * * <pre> * StringUtils.substringAfter(null, *) = null * StringUtils.substringAfter("", *) = "" * StringUtils.substringAfter(*, null) = "" * StringUtils.substringAfter("abc", "a") = "bc" * StringUtils.substringAfter("abcba", "b") = "cba" * StringUtils.substringAfter("abc", "c") = "" * StringUtils.substringAfter("abc", "d") = "" * StringUtils.substringAfter("abc", "") = "abc" * </pre> * * @param str ? * @param separator SEPARATOR * @return ?, ?? null? <code>null</code> */ public static String substringAfter(String str, String separator) { return StringUtils.substringAfter(str, separator); } /** * ?? separator ?? .<br> * * <pre> * StringUtils.substringAfterLast(null, *) = null * StringUtils.substringAfterLast("", *) = "" * StringUtils.substringAfterLast(*, "") = "" * StringUtils.substringAfterLast(*, null) = "" * StringUtils.substringAfterLast("abc", "a") = "bc" * StringUtils.substringAfterLast("abcba", "b") = "a" * StringUtils.substringAfterLast("abc", "c") = "" * StringUtils.substringAfterLast("a", "a") = "" * StringUtils.substringAfterLast("a", "z") = "" * </pre> * * @param str ? * @param separator SEPARATOR * @return ?, ?? null? <code>null</code> */ public static String substringAfterLast(String str, String separator) { return StringUtils.substringAfterLast(str, separator); } // SubStringAfter/SubStringBefore //----------------------------------------------------------------------- /** * ?? ? SEPARATOR ?? .<br> * * <pre> * StringUtils.substringBefore(null, *) = null * StringUtils.substringBefore("", *) = "" * StringUtils.substringBefore("abc", "a") = "" * StringUtils.substringBefore("abcba", "b") = "a" * StringUtils.substringBefore("abc", "c") = "ab" * StringUtils.substringBefore("abc", "d") = "abc" * StringUtils.substringBefore("abc", "") = "" * StringUtils.substringBefore("abc", null) = "abc" * </pre> * * @param str ? * @param separator SEPARATOR * @return ?, ?? null? <code>null</code> */ public static String substringBefore(String str, String separator) { return StringUtils.substringBefore(str, separator); } /** * ?? separator ?? .<br> * * <pre> * StringUtils.substringBeforeLast(null, *) = null * StringUtils.substringBeforeLast("", *) = "" * StringUtils.substringBeforeLast("abcba", "b") = "abc" * StringUtils.substringBeforeLast("abc", "c") = "ab" * StringUtils.substringBeforeLast("a", "a") = "" * StringUtils.substringBeforeLast("a", "z") = "a" * StringUtils.substringBeforeLast("a", null) = "a" * StringUtils.substringBeforeLast("a", "") = "a" * </pre> * * @param str ? * @param separator SEPARATOR * @return ?, ?? null? <code>null</code> */ public static String substringBeforeLast(String str, String separator) { return StringUtils.substringBeforeLast(str, separator); } // Substring between //----------------------------------------------------------------------- /** * ?? TAG?? ?? .<br> * * <pre> * StringUtils.substringBetween(null, *) = null * StringUtils.substringBetween("", "") = "" * StringUtils.substringBetween("", "tag") = null * StringUtils.substringBetween("tagabctag", null) = null * StringUtils.substringBetween("tagabctag", "") = "" * StringUtils.substringBetween("tagabctag", "tag") = "abc" * </pre> * * @param str ? * @param tag TAG * @return ?, ?? TAG ? <code>null</code> */ public static String substringBetween(String str, String tag) { return StringUtils.substringBetween(str, tag); } /** * ?? OPEN CLOSE ?? ?? .<br> * * <pre> * StringUtils.substringBetween("wx[b]yz", "[", "]") = "b" * StringUtils.substringBetween(null, *, *) = null * StringUtils.substringBetween(*, null, *) = null * StringUtils.substringBetween(*, *, null) = null * StringUtils.substringBetween("", "", "") = "" * StringUtils.substringBetween("", "", "]") = null * StringUtils.substringBetween("", "[", "]") = null * StringUtils.substringBetween("yabcz", "", "") = "" * StringUtils.substringBetween("yabcz", "y", "z") = "abc" * StringUtils.substringBetween("yabczyabcz", "y", "z") = "abc" * </pre> * * @param str ? * @param open OPEN * @param close CLOSE * @return ?, ?? TAG ? <code>null</code> */ public static String substringBetween(String str, String open, String close) { return StringUtils.substringBetween(str, open, close); } /** * ? OPEN CLOSE? ? ?? .<br> * * <pre> * StringUtils.substringsBetween("[a][b][c]", "[", "]") = ["a","b","c"] * StringUtils.substringsBetween(null, *, *) = null * StringUtils.substringsBetween(*, null, *) = null * StringUtils.substringsBetween(*, *, null) = null * StringUtils.substringsBetween("", "[", "]") = [] * </pre> * * @param str ? * @param open OPEN * @param close CLOSE * @return ?, ? OPEN ? CLOSE null? <code>null</code> */ public static String[] substringsBetween(String str, String open, String close) { return StringUtils.substringsBetween(str, open, close); } /** * ? ? ? ? .<br> * * <pre> * StringUtils.swapCase(null) = null * StringUtils.swapCase("") = "" * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" * </pre> * * @param str the String to swap case, may be null * @return ?, ?? null? <code>null</code> */ public static String swapCase(String str) { return StringUtils.swapCase(str); } /** * ? ? <br><br> * * StringUtils.swapFirstLetterCase("java") = "Java" * * @param str ? * @return ? ? ? */ public static String swapFirstLetterCase(String str) { StringBuilder sbuf = new StringBuilder(str); sbuf.deleteCharAt(0); if (Character.isLowerCase(str.substring(0, 1).toCharArray()[0])) { sbuf.insert(0, str.substring(0, 1).toUpperCase()); } else { sbuf.insert(0, str.substring(0, 1).toLowerCase()); } return sbuf.toString(); } /** * String? delimiter ? tokenize String[] .<br> * Java? StringTokenizer ? .<br> * ? ? (space)? (trim) .<br> * StringTokenizer ?, ?? delimiter ? token? ? .<br> * String? null? null? return.<br> * delimiter null? String? ? element String[] return.<br><br> * * StringUtils.tokenizeToStringArray("aaa.bbb.ccc.ddd", ".", true, true) = {"aaa", "bbb", "ccc", "ddd"} * * @param str ? * @param separator ? * @param trimTokens * @return an array of parsed Strings */ public static String[] tokenizeToStringArray(String str, String separator, boolean trimTokens) { if (str == null) { return null; } if (separator == null) { return new String[] { str }; } StringTokenizer st = new StringTokenizer(str, separator); List<String> tokens = new ArrayList<String>(); do { if (!st.hasMoreTokens()) { break; } String token = st.nextToken(); if (trimTokens) { token = token.trim(); } if (token.length() != 0) { tokens.add(token); } } while (true); return tokens.toArray(new String[tokens.size()]); } /** * ? ? ? '-' ?? ? ? ? .<br><br> * * StringUtils.toTelephoneNumberFormat("032-123-4567") = "032-123-4567"<br> * StringUtils.toTelephoneNumberFormat("021234567") = "02-123-4567"<br> * StringUtils.toTelephoneNumberFormat("0212345678") = "02-1234-5678"<br> * StringUtils.toTelephoneNumberFormat("1234567") = "123-4567" * * @param str ? * @return ? ? */ public static String toTelephoneNumberFormat(String str) { int endNumberDigit = 4; int minNumberDigit = 7; if (StringUtils.isEmpty(str)) { return null; } String origin = str.trim(); String tempNumber; int originLength = origin.length(); // extract numeric chars only if (StringUtils.isNotNumeric(origin)) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < originLength; i++) { if (Character.isDigit(origin.charAt(i))) { sb.append(origin.charAt(i)); } } tempNumber = sb.toString(); } else { tempNumber = origin; } int numberLength = tempNumber.length(); if (numberLength < minNumberDigit) { return tempNumber; } String firstNumber = ""; String secondNumber = ""; String thirdNumber = ""; if (tempNumber.charAt(0) == '0') { // local number or mobile number if (tempNumber.charAt(1) == '2') { // Seoul firstNumber = tempNumber.substring(0, 2); secondNumber = tempNumber.substring(2, numberLength - endNumberDigit); thirdNumber = tempNumber.substring(numberLength - endNumberDigit, numberLength); // split last 4 digits } else { // local number or mobile number firstNumber = tempNumber.substring(0, 3); secondNumber = tempNumber.substring(3, numberLength - endNumberDigit); thirdNumber = tempNumber.substring(numberLength - endNumberDigit, numberLength); // split last 4 digits } return firstNumber + "-" + secondNumber + "-" + thirdNumber; } else { // telephone number without local number firstNumber = tempNumber.substring(0, numberLength - endNumberDigit); secondNumber = tempNumber.substring(numberLength - endNumberDigit, numberLength); return firstNumber + "-" + secondNumber; } } /** * 6? ? String? "111-111" ? ? .<br> * String? 6? ? "" return.<br> * String? ? ? ? ""? return.<br><br> * * StringUtils.toZipCodePattern("111111") = "111-111" * * @param str ? * @return ? ? */ public static String toZipCodePattern(String str) { if (str == null) { return ""; } if (str.length() != 6 || !isDigit(str)) { return ""; } else { StringBuffer buffer = new StringBuffer(); buffer.append(str.substring(0, 3)); buffer.append('-'); buffer.append(str.substring(3, 6)); return buffer.toString(); } } /** * ?? ? ? .<br> * * <pre> * StringUtils.trim(null) = null * StringUtils.trim("") = "" * StringUtils.trim(" ") = "" * StringUtils.trim("abc") = "abc" * StringUtils.trim(" abc ") = "abc" * </pre> * * @param str ? * @return null ? ? null * "" ? "" */ public static String trim(String str) { return StringUtils.trim(str); } /** * ? ?? ? ? ? trim.<br><br> * * StringUtils.trim("Anyframe*Java", "*") = "AnyframeJava" * * @param origString ? * @param trimString trim ? * @return ?? trim ?? trim ? */ public static String trim(String origString, String trimString) { int startPosit = origString.indexOf(trimString); if (startPosit != -1) { int endPosit = trimString.length() + startPosit; return origString.substring(0, startPosit) + origString.substring(endPosit); } return origString; } /** * ? NULL? ? , ? ? <br> * ? .<br> * <pre> * StringUtils.trimToEmpty(null) = "" * StringUtils.trimToEmpty("") = "" * StringUtils.trimToEmpty(" ") = "" * StringUtils.trimToEmpty("abc") = "abc" * StringUtils.trimToEmpty(" abc ") = "abc" * </pre> * * @param str ? * @return null ? ? ""? "" */ public static String trimToEmpty(String str) { return StringUtils.trimToEmpty(str); } /** * ?? ? ? .<br> * ? NULL <br> * * <pre> * StringUtils.trimToNull(null) = null * StringUtils.trimToNull("") = null * StringUtils.trimToNull(" ") = null * StringUtils.trimToNull("abc") = "abc" * StringUtils.trimToNull(" abc ") = "abc" * </pre> * * @param str ? * @return null ? ? ""? null */ public static String trimToNull(String str) { return StringUtils.trimToNull(str); } /** * ?? ? ? .<br> * * <pre> * StringUtils.uncapitalize(null) = null * StringUtils.uncapitalize("") = "" * StringUtils.uncapitalize("Cat") = "cat" * StringUtils.uncapitalize("CAT") = "cAT" * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String uncapitalize(String str) { return StringUtils.uncapitalize(str); } /** * ?? ? .<br> * * <pre> * StringUtils.upperCase(null) = null * StringUtils.upperCase("") = "" * StringUtils.upperCase("aBc") = "ABC" * </pre> * * @param str ? * @return ?, ?? null? <code>null</code> */ public static String upperCase(String str) { return StringUtils.upperCase(str); } /** * ?? ?? ? .<br> * * <pre> * StringUtils.upperCase(null, Locale.ENGLISH) = null * StringUtils.upperCase("", Locale.ENGLISH) = "" * StringUtils.upperCase("aBc", Locale.ENGLISH) = "ABC" * </pre> * * @param str ? * @param locale ? * @return ?, ?? null? <code>null</code> */ public static String upperCase(String str, Locale locale) { return StringUtils.upperCase(str, locale); } }