返回指定字符串之前的所有字符:
@param str the String to get a substring from, may be null
@param separator the String to search for, may be null
@return the substring before the first occurance of the separator,null if null String input
@since 2.0
public static String substringBefore(String str, String separator)
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"
返回指定字符串之后的所有字符:
Gets the substring after the first occurance of a separator.
The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
A null separator will return the empty string if the
nput string is not null.
@param str the String to get a substring from, may be null
@param separator the String to search for, may be null
@return the substring after the first occurance of the separator,
null if null String input
@since 2.0
public static String substringAfter(String str, String separator)
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"
返回最后一个指定字符串之前的所有字符:
Gets the substring before the last occurance of a separator.
The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
An empty or null separator will return the input string.
@param str the String to get a substring from, may be null
@param separator the String to search for, may be null
@return the substring before the last occurance of the separator,
null if null String input
@since 2.0
public static String substringBeforeLast(String str, String separator)
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"
返回最后一个指定字符串之后的所有字符:
Gets the substring after the last occurance of a separator.
The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
An empty or null separator will return the empty string if
the input string is not null.
@param str the String to get a substring from, may be null
@param separator the String to search for, may be null
@return the substring after the last occurance of the separator,
null if null String input
@since 2.0
public static String substringAfterLast(String str, String separator)
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") = ""
Replacing(字符串替换)-> 以指定字符串替换原来字符串的的指定字符串:
@param text text to search and replace in, may be null
@param repl the String to search for, may be null
@param with the String to replace with, may be null
@return the text with any replacements processed,
null if null String input
@see #replace(String text, String repl, String with, int max)
public static String replace(String text, String repl, String with)
StringUtils.replace(null, *, *) = null
StringUtils.replace("", *, *) = ""
StringUtils.replace("aba", null, null) = "aba"
StringUtils.replace("aba", null, null) = "aba"
StringUtils.replace("aba", "a", null) = "aba"
StringUtils.replace("aba", "a", "") = "aba"
StringUtils.replace("aba", "a", "z") = "zbz"
Replacing(字符串替换)-> 以指定字符串最大替换原来字符串的的指定字符串:
@param text text to search and replace in, may be null
@param repl the String to search for, may be null
@param with the String to replace with, may be null
@param max maximum number of values to replace, or -1 if no maximum
@return the text with any replacements processed,
null if null String input
public static String replace(String text, String repl, String with, int max)
StringUtils.replace(null, *, *, *) = null
StringUtils.replace("", *, *, *) = ""
StringUtils.replace("abaa", null, null, 1) = "abaa"
StringUtils.replace("abaa", null, null, 1) = "abaa"
StringUtils.replace("abaa", "a", null, 1) = "abaa"
StringUtils.replace("abaa", "a", "", 1) = "abaa"
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"
Case conversion(大小写转换)-> 将一个字符串变为大写:
@param str the String to upper case, may be null
@return the upper cased String, null if null String input
public static String upperCase(String str)
StringUtils.upperCase(null) = null
StringUtils.upperCase("") = ""
StringUtils.upperCase("aBc") = "ABC"
Case conversion(大小写转换)-> 将一个字符串转换为小写:
@param str the String to lower case, may be null
@return the lower cased String, null if null String input
public static String lowerCase(String str)
StringUtils.lowerCase(null) = null
StringUtils.lowerCase("") = ""
StringUtils.lowerCase("aBc") = "abc"
Case conversion(大小写转换)-> 将字符串中的首字母大写:
@param str the String to capitalize, may be null
@return the capitalized String, null if null String input
@see /WordUtils#capitalize(String)
@see /uncapitalize(String)
@since 2.0
public static String capitalize(String str)
StringUtils.capitalize(null) = null
StringUtils.capitalize("") = ""
StringUtils.capitalize("cat") = "Cat"
StringUtils.capitalize("cAt") = "CAt"