加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java开发_org.apache.commons.lang.StringUtils工具类源码

发布时间:2020-12-14 06:28:16 所属栏目:Java 来源:网络整理
导读:在之前写了一篇关于""和null区别的文章。 下面是文章的地址: 下面看看org.apache.commons.lang.StringUtils工具类源码 Operations on { null safe. IsEmpty/IsBlank Trim/Strip Equals startsWith endsWith IndexOf/LastIndexOf/Contains IndexOfAny/LastIn

在之前写了一篇关于""和null区别的文章。

下面是文章的地址:

下面看看org.apache.commons.lang.StringUtils工具类源码

Operations on { null safe.

IsEmpty/IsBlank Trim/Strip Equals startsWith endsWith IndexOf/LastIndexOf/Contains IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut ContainsOnly/ContainsNone/ContainsAny Substring/Left/Right/Mid SubstringBefore/SubstringAfter/SubstringBetween Split/Join Remove/Delete Replace/Overlay Chomp/Chop LeftPad/RightPad/Center/Repeat UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize CountMatches IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable DefaultString Reverse/ReverseDelimited Abbreviate Difference LevensteinDistance The StringUtils class defines certain words related to null - null empty - a zero-length string ("") space - the space character (' ',char 32) whitespace - the characters defined by { trim - the characters <= 32 as in { StringUtils handles null input Strings quietly. null input will return null. boolean or int is being returned A side effect of the null handling is that a NullPointerException should be considered a bug in StringUtils (except for deprecated methods).

Methods in this class give sample code to explain their operation. * is used to indicate any input including null.

#ThreadSafe#

"". String EMPTY = "" INDEX_NOT_FOUND = -1 The maximum size to which the padding constant(s) can expand.

PAD_LIMIT = 8192 StringUtils instances should NOT be constructed in StringUtils.trim(" foo ");.

This constructor is public to permit tools that require a JavaBean Checks if a String is empty ("") or null.

NOTE: This method changed in Lang version 2.0. true if the String is empty or null str == || str.length() == 0 Checks if a String is not empty ("") and not null.

true if the String is not empty and not null ! Checks if a String is whitespace,empty ("") or null.

true if the String is null,empty or whitespace (str == || (strLen = str.length()) == 0 ( i = 0; i < strLen; i++ ((Character.isWhitespace(str.charAt(i)) == Checks if a String is not empty (""),not null and not whitespace only.

true if the String is ! Removes control characters (char &lt;= 32) from both null by returning null str == ? Removes control characters (char &lt;= 32) from both null by returning null.

The String is trimmed using { To trim your choice of characters,use the null if null String input str == ? Removes control characters (char &lt;= 32) from both null if the String is null. The String is trimmed using { null if only chars &lt;= 32,empty or null String input String ts = isEmpty(ts) ? Removes control characters (char &lt;= 32) from both null. The String is trimmed using { null input str == ? Strips whitespace from the start and end of a String.

This is similar to { A null input String returns null.

null if null String input strip(str, Strips whitespace from the start and end of a String returning null if the String is empty ("") after the strip.

This is similar to { null if whitespace,empty or null String input (str == str = strip(str, str.length() == 0 ? Strips whitespace from the start and end of a String returning null input.

This is similar to { null input str == ? EMPTY : strip(str, Strips any of a set of characters from the start and end of a String. A null input String returns null. If the stripChars String is null,whitespace is null if null String input str = Strips any of a set of characters from the start of a String.

A null input String returns null. If the stripChars String is null,whitespace is null if null String input (str == || (strLen = str.length()) == 0 start = 0 (stripChars == ((start != strLen) && start++ } (stripChars.length() == 0 } ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != start++ Strips any of a set of characters from the end of a String.

A null input String returns null. If the stripChars String is null,whitespace is null if null String input (str == || (end = str.length()) == 0 (stripChars == ((end != 0) && Character.isWhitespace(str.charAt(end - 1 end-- } (stripChars.length() == 0 } ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != end-- str.substring(0 Strips whitespace from the start and end of every String in an array. A new array is returned each time,except for length zero. null array will return null. null array entry will be ignored.

null if null array input stripAll(strs, Strips any of a set of characters from the start and end of every A new array is returned each time,except for length zero. null array will return null. null array entry will be ignored. null stripChars will strip whitespace as defined by null if null array input (strs == || (strsLen = strs.length) == 0 String[] newArr = ( i = 0; i < strsLen; i++ newArr[i] = Compares two Strings,returning true if they are equal.

nulls are handled without exceptions. Two null true if the Strings are equal,case sensitive,or null str1 == ? str2 == Compares two Strings,returning true if they are equal ignoring nulls are handled without exceptions. Two null true if the Strings are equal,case insensitive,or null str1 == ? str2 == Finds the first index within a String,handling null. A null or empty ("") String will return INDEX_NOT_FOUND (-1).

null string input indexOf(String str, Finds the first index within a String from a start position, null. A null or empty ("") String will return (INDEX_NOT_FOUND) -1. -1.

null string input indexOf(String str, searchChar, Finds the first index within a String,handling null. A null String will return -1.

null string input (str == || searchStr == Finds the n-th index within a String,handling null. A null String will return -1.

Note that 'head(String str,int n)' may be implemented as:

searchStr to find -1 (INDEX_NOT_FOUND) if no match or null string input ordinalIndexOf(String str,String searchStr, ordinalIndexOf(str,searchStr,ordinal, Finds the n-th index within a String,handling null. A null String will return -1.

searchStr to find -1 (INDEX_NOT_FOUND) if no match or null string input ordinalIndexOf(String str, ordinal, (str == || searchStr == || ordinal <= 0 (searchStr.length() == 0 lastIndex ? str.length() : 0 found = 0 index = lastIndex ? index = str.lastIndexOf(searchStr,index - 1 } index = str.indexOf(searchStr,index + 1 (index < 0 found++ } (found < Finds the first index within a String,handling null. A null String will return -1. null string input indexOf(String str, (str == || searchStr == str.length for "",hence (searchStr.length() == 0 && startPos >= Case in-sensitive find of the first index within a String.

A null String will return -1. null string input indexOfIgnoreCase(str,0 Case in-sensitive find of the first index within a String A null String will return -1. null string input indexOfIgnoreCase(String str, (str == || searchStr == (startPos < 0 startPos = 0 endLimit = (str.length() - searchStr.length()) + 1 (startPos > (searchStr.length() == 0 ( i = startPos; i < endLimit; i++ (str.regionMatches(,i,0 Finds the last index within a String,handling null. A null or empty ("") String will return -1.

null string input lastIndexOf(String str, Finds the last index within a String from a start position, null. A null or empty ("") String will return -1. -1. null string input lastIndexOf(String str, Finds the last index within a String,handling null. A null String will return -1.

null string input (str == || searchStr == Finds the n-th last index within a String,handling null. A null String will return -1.

Note that 'tail(String str,int n)' may be implemented as:

searchStr to find -1 (INDEX_NOT_FOUND) if no match or null string input lastOrdinalIndexOf(String str, ordinalIndexOf(str, Finds the first index within a String,handling null. A null String will return -1. -1. null string input lastIndexOf(String str, (str == || searchStr == Case in-sensitive find of the last index within a String.

A null String will return -1. -1. null string input (str == || searchStr == Case in-sensitive find of the last index within a String A null String will return -1. -1. null string input lastIndexOfIgnoreCase(String str, (str == || searchStr == (startPos > (str.length() - startPos = str.length() - (startPos < 0 (searchStr.length() == 0 ( i = startPos; i >= 0; i-- (str.regionMatches(,searchStr.length())) { Checks if String contains a search character,handling null. A null or empty ("") String will return false.

null string input contains(String str, str.indexOf(searchChar) >= 0 Checks if String contains a search String,handling null. A null String will return false.

null string input (str == || searchStr == str.indexOf(searchStr) >= 0 Checks if String contains a search String irrespective of case, null. Case-insensitivity is defined as by A null String will return false.

null string input (str == || searchStr == len = max = str.length() - ( i = 0; i <= max; i++ (str.regionMatches(,len)) { Search a String to find the first index of any A null String will return -1. null or zero length search array will return -1.

indexOfAny(String str, (isEmpty(str) || csLen = csLast = csLen - 1 searchLen = searchLast = searchLen - 1 ( i = 0; i < csLen; i++ ch = ( j = 0; j < searchLen; j++ (searchChars[j] == (i < csLast && j < searchLast && (searchChars[j + 1] == str.charAt(i + 1 } Search a String to find the first index of any A null String will return -1. null search string will return -1.

(isEmpty(str) || Checks if the String contains any character in the given A null String will return false. null or zero length search array will return false.

true if any of the chars are found, false if no match or null input containsAny(String str, (isEmpty(str) || csLength = searchLength = csLast = csLength - 1 searchLast = searchLength - 1 ( i = 0; i < csLength; i++ ch = ( j = 0; j < searchLength; j++ (searchChars[j] == (j == (i < csLast && searchChars[j + 1] == str.charAt(i + 1 } null String will return false. A null search string will return false. true if any of the chars are found,false if no match or null input (searchChars == Search a String to find the first index of any A null String will return -1. null or zero length search array will return -1.

indexOfAnyBut(String str, (isEmpty(str) || csLen = csLast = csLen - 1 searchLen = searchLast = searchLen - 1 ( i = 0; i < csLen; i++ ch = ( j = 0; j < searchLen; j++ (searchChars[j] == (i < csLast && j < searchLast && (searchChars[j + 1] == str.charAt(i + 1 } Search a String to find the first index of any A null String will return -1. null or empty search string will return -1.

(isEmpty(str) || strLen = ( i = 0; i < strLen; i++ ch = chFound = searchChars.indexOf(ch) >= 0 (i + 1 < strLen && ch2 = str.charAt(i + 1 (chFound && searchChars.indexOf(ch2) < 0 } (! Checks if the String contains only certain characters.

A null String will return false. null valid character array will return false. true.

containsOnly(String str, ((valid == ) || (str == (str.length() == 0 (valid.length == 0 indexOfAnyBut(str,valid) == Checks if the String contains only certain characters.

A null String will return false. null valid character String will return false. true.

(str == || validChars == Checks that the String does not contain certain characters.

A null String will return true. null invalid character array will return true. containsNone(String str, (str == || searchChars == csLen = csLast = csLen - 1 searchLen = searchLast = searchLen - 1 ( i = 0; i < csLen; i++ ch = ( j = 0; j < searchLen; j++ (searchChars[j] == (j == (i < csLast && searchChars[j + 1] == str.charAt(i + 1 } Checks that the String does not contain certain characters.

A null String will return true. null invalid character array will return true. (str == || invalidChars == Find the first index of any of a set of potential substrings.

A null String will return -1. null or zero length search array will return -1. null search array entry will be ignored,but a search 0 if str is not ((str == ) || (searchStrs == sz = ret = tmp = 0 ( i = 0; i < sz; i++ String search = (search == tmp = (tmp == (tmp < ret = (ret == Integer.MAX_VALUE) ? Find the latest index of any of a set of potential substrings.

A null String will return -1. null search array will return -1. null or zero length search array entry will be ignored, str str is not null. This method uses { ((str == ) || (searchStrs == sz = ret = tmp = 0 ( i = 0; i < sz; i++ String search = (search == tmp = (tmp > ret = Gets a substring from the specified String avoiding exceptions.

A negative start position can be used to start n A null String will return null. null if null String input String substring(String str, (str == (start < 0 start = str.length() + start; (start < 0 start = 0 (start > Gets a substring from the specified String avoiding exceptions.

A negative start position can be used to start/end n The returned substring starts with the character in the start end position. All position counting is start = 0. Negative start and end positions can be used to If start is not strictly to the left of end,"" null if null String input String substring(String str, start, (str == (end < 0 end = str.length() + end; (start < 0 start = str.length() + start; (end > end = (start > (start < 0 start = 0 (end < 0 end = 0 Gets the leftmost len characters of a String.

If len characters are not available,or the null,the String will be returned without null if null String input String left(String str, (str == (len < 0 (str.length() <= str.substring(0 Gets the rightmost len characters of a String.

If len characters are not available,or the String null,the String will be returned without an null if null String input String right(String str, (str == (len < 0 (str.length() <= str.substring(str.length() - Gets len characters from the middle of a String.

If len characters are not available,the remainder null,null will be returned. str.

null if null String input String mid(String str, pos, (str == (len < 0 || pos > (pos < 0 pos = 0 (str.length() <= (pos + str.substring(pos,pos + Gets the substring before the first occurrence of a separator. A null string input will return null. null separator will return the input string.

If nothing is found,the string input is returned.

null if null String input (isEmpty(str) || separator == (separator.length() == 0 pos = (pos == str.substring(0 Gets the substring after the first occurrence of a separator. A null string input will return null. null separator will return the empty string if the null.

If nothing is found,the empty string is returned.

null if null String input (separator == pos = (pos == str.substring(pos + Gets the substring before the last occurrence of a separator. A null string input will return null. null separator will return the input string.

If nothing is found,the string input is returned.

null if null String input (isEmpty(str) || pos = (pos == str.substring(0 Gets the substring after the last occurrence of a separator. A null string input will return null. null separator will return the empty string if null.

If nothing is found,the empty string is returned.

null if null String input pos = (pos == INDEX_NOT_FOUND || pos == (str.length() - str.substring(pos + Gets the String that is nested in between two instances of the A null input String returns null. null tag returns null.

null if no match Gets the String that is nested in between two Strings. A null input String returns null. null open/close returns null (no match). null if no match (str == || open == || close == start = (start != end = str.indexOf(close,start + (end != str.substring(start + Searches a String for substrings delimited by a start and end tag, A null input String returns null. null open/close returns null (no match). null (no match).

null if no match (str == || isEmpty(open) || strLen = (strLen == 0 closeLen = openLen = List list = pos = 0 (pos < (strLen - start = (start < 0 start += end = (end < 0 pos = end + (String[]) list.toArray( Gets the String that is nested in between two instances of the A null input String returns null. null tag returns null.

null if no match Gets the String that is nested in between two Strings. A null input String returns null. null open/close returns null (no match). null if no match Splits the provided text into an array,using whitespace as the The separator is not included in the returned String array. A null input String returns null.

null if null String input split(str,,-1 Splits the provided text into an array,separator specified. The separator is not included in the returned String array. A null input String returns null.

null if null String input String[] split(String str, splitWorker(str,separatorChar, Splits the provided text into an array,separators specified. The separator is not included in the returned String array. A null input String returns null. null separatorChars splits on whitespace.

null splits on whitespace null if null String input splitWorker(str,separatorChars,-1, Splits the provided text into an array with a maximum length, The separator is not included in the returned String array. A null input String returns null. null separatorChars splits on whitespace.

If more than max delimited substrings are found,the last max - 1 null splits on whitespace null if null String input String[] split(String str,String separatorChars, splitWorker(str,max, Splits the provided text into an array,separator string specified.

The separator(s) will not be included in the returned String array. A null input String returns null. null separator splits on whitespace.

null splits on whitespace null if null String was input splitByWholeSeparatorWorker( str,separator, Splits the provided text into an array,separator string specified. max substrings.

The separator(s) will not be included in the returned String array. A null input String returns null. null separator splits on whitespace.

null splits on whitespace null if null String was input String[] splitByWholeSeparator( String str,String separator, splitByWholeSeparatorWorker(str, Splits the provided text into an array,separator string specified.

The separator is not included in the returned String array. A null input String returns null. null separator splits on whitespace.

null splits on whitespace null if null String was input splitByWholeSeparatorWorker(str, Splits the provided text into an array,separator string specified. max substrings.

The separator is not included in the returned String array. A null input String returns null. null separator splits on whitespace.

null splits on whitespace null if null String was input String[] splitByWholeSeparatorPreserveAllTokens(String str, splitByWholeSeparatorWorker(str, splitByWholeSeparatorPreserveAllTokens methods. null null splits on whitespace true,adjacent separators are false,adjacent null if null String input String[] splitByWholeSeparatorWorker(String str, (str == len = (len == 0 ((separator == ) || splitWorker(str, separatorLength = ArrayList substrings = numberOfSubstrings = 0 beg = 0 end = 0 (end < end = (end > -1 (end > numberOfSubstrings += 1 (numberOfSubstrings == end = } beg = end + } numberOfSubstrings += 1 (numberOfSubstrings == end = } beg = end + } end = (String[]) substrings.toArray( Splits the provided text into an array,using whitespace as the The separator is not included in the returned String array. A null input String returns null.

null null if null String input splitWorker(str, Splits the provided text into an array,separator specified, The separator is not included in the returned String array. A null input String returns null.

null null splits on whitespace null if null String input String[] splitPreserveAllTokens(String str, splitWorker(str, split and splitPreserveAllTokens methods that do not return a null true,adjacent separators are false,adjacent null if null String input String[] splitWorker(String str, separatorChar, (str == len = (len == 0 List list = i = 0,start = 0 match = lastMatch = (i < (str.charAt(i) == (match || match = lastMatch = start = ++ lastMatch = match = i++ (match || (preserveAllTokens && (String[]) list.toArray( Splits the provided text into an array,separators specified, The separator is not included in the returned String array. A null input String returns null. null separatorChars splits on whitespace.

null null splits on whitespace null if null String input splitWorker(str, Splits the provided text into an array with a maximum length, The separator is not included in the returned String array. A null input String returns null. null separatorChars splits on whitespace.

If more than max delimited substrings are found,the last max - 1 null null splits on whitespace null if null String input String[] splitPreserveAllTokens(String str, splitWorker(str, split and splitPreserveAllTokens methods that return a maximum array null true,adjacent separators are false,adjacent null if null String input String[] splitWorker(String str, max, (str == len = (len == 0 List list = sizePlus1 = 1 i = 0,start = 0 match = lastMatch = (separatorChars == (i < (match || lastMatch = (sizePlus1++ == i = lastMatch = match = start = ++ lastMatch = match = i++ } (separatorChars.length() == 1 sep = separatorChars.charAt(0 (i < (str.charAt(i) == (match || lastMatch = (sizePlus1++ == i = lastMatch = match = start = ++ lastMatch = match = i++ } (i < (separatorChars.indexOf(str.charAt(i)) >= 0 (match || lastMatch = (sizePlus1++ == i = lastMatch = match = start = ++ lastMatch = match = i++ (match || (preserveAllTokens && (String[]) list.toArray( Splits a String by Character type as returned by java.lang.Character.getType(char). Groups of contiguous null null if null String input splitByCharacterType(str, Splits a String by Character type as returned by java.lang.Character.getType(char). Groups of contiguous Character.UPPERCASE_LETTER,if any,immediately Character.LOWERCASE_LETTER Character.UPPERCASE_LETTER token. null null if null String input splitByCharacterType(str, Splits a String by Character type as returned by java.lang.Character.getType(char). Groups of contiguous camelCase is true, Character.UPPERCASE_LETTER, Character.LOWERCASE_LETTER Character.UPPERCASE_LETTER token. null null if null String input String[] splitByCharacterType(String str, (str == (str.length() == 0 [] c = List list = tokenStart = 0 currentType = ( pos = tokenStart + 1; pos < c.length; pos++ type = (type == (camelCase && type == Character.LOWERCASE_LETTER && currentType == newTokenStart = pos - 1 (newTokenStart != list.add( String(c,tokenStart,newTokenStart - tokenStart = } list.add( String(c,pos - tokenStart = currentType = list.add( String(c,c.length - (String[]) list.toArray( Joins the provided elements into a single String.

No separator is added to the joined String. null if null array input join(array, Joins the elements of the provided array into a single String No separator is added to the joined String. null if null array input join(array, Joins the elements of the provided array into a single String No delimiter is added before or after the list. null if null array input String join(Object[] array, (array == join(array,array.length); Joins the elements of the provided array into a single String No delimiter is added before or after the list. null if null array input String join(Object[] array, separator, startIndex, (array == bufSize = (endIndex - (bufSize <= 0 bufSize *= ((array[startIndex] == ? 16 : array[startIndex].toString().length()) + 1 StrBuilder buf = ( i = startIndex; i < endIndex; i++ (i > (array[i] != Joins the elements of the provided array into a single String No delimiter is added before or after the list. null separator is the same as an empty String (""). null if null array input (array == join(array,array.length); Joins the elements of the provided array into a single String No delimiter is added before or after the list. null separator is the same as an empty String (""). null if null array input String join(Object[] array, (array == (separator == separator = 0: Len = NofStrings *(len(firstString) + len(separator)) bufSize = (endIndex - (bufSize <= 0 bufSize *= ((array[startIndex] == ? 16 + StrBuilder buf = ( i = startIndex; i < endIndex; i++ (i > (array[i] != Joins the elements of the provided Iterator into No delimiter is added before or after the list. Null objects or empty See the examples here: { Iterator of values to join together,may be null null if null iterator input String join(Iterator iterator, (iterator == (! Object first = (! StrBuilder buf = StrBuilder(256); (first != Object obj = (obj != Joins the elements of the provided Iterator into No delimiter is added before or after the list. null separator is the same as an empty String ("").

See the examples here: { Iterator of values to join together,may be null null if null iterator input (iterator == (! Object first = (! StrBuilder buf = StrBuilder(256); (first != (separator != Object obj = (obj != Joins the elements of the provided Collection into No delimiter is added before or after the list. Null objects or empty See the examples here: { Collection of values to join together,may be null null if null iterator input String join(Collection collection, (collection == Joins the elements of the provided Collection into No delimiter is added before or after the list. null separator is the same as an empty String ("").

See the examples here: { Collection of values to join together,may be null null if null iterator input (collection == Deletes all 'space' characters from a String as defined by This is the only StringUtils method that uses the isSpace definition. You are advised to use Spaces are defined as {' ','t','r','n','b'} isSpace method.

null if null String input (str == CharSetUtils.delete(str," trnb" Deletes all whitespaces from a String as defined by null if null String input sz = [] chs = count = 0 ( i = 0; i < sz; i++ (! chs[count++] = (count == String(chs,count); Removes a substring only if it is at the begining of a source string, A null source string will return null. null search string will return the source string.

null if null String input (isEmpty(str) || Case insensitive removal of a substring if it is at the begining of a source string, A null source string will return null. null search string will return the source string.

null if null String input (isEmpty(str) || Removes a substring only if it is at the end of a source string, A null source string will return null. null search string will return the source string.

null if null String input (isEmpty(str) || str.substring(0,str.length() - Case insensitive removal of a substring if it is at the end of a source string, A null source string will return null. null search string will return the source string.

null if null String input (isEmpty(str) || str.substring(0,str.length() - Removes all occurrences of a substring from within the source string.

A null source string will return null. null remove string will return the source string. null if null String input (isEmpty(str) || replace(str,remove,EMPTY,-1 Removes all occurrences of a character from within the source string.

A null source string will return null. null if null String input String remove(String str, (isEmpty(str) || str.indexOf(remove) == [] chars = pos = 0 ( i = 0; i < chars.length; i++ (chars[i] != chars[pos++] = String(chars,pos); Replaces a String with another String inside a larger String,once.

A null reference passed to this method is a no-op.

null if null String input replace(text,searchString,replacement,1 Replaces all occurrences of a String within another String.

A null reference passed to this method is a no-op.

null if null String input replace(text,-1 Replaces a String with another String inside a larger String, max values of the search String.

A null reference passed to this method is a no-op.

-1 if no maximum null if null String input String replace(String text, (isEmpty(text) || isEmpty(searchString) || replacement == || max == 0 start = 0 end = (end == replLength = increase = replacement.length() - increase = (increase < 0 ? 0 increase *= (max < 0 ? 16 : (max > 64 ? 64 StrBuilder buf = StrBuilder(text.length() + (end != start = end + (--max == 0 end = null reference passed to this method is a no-op,or if null if replaceEach(text,searchList,replacementList,,0 null reference passed to this method is a no-op,or if null if timeToLive = searchList == ? 0 replaceEach(text, null reference passed to this method is a no-op,or if null if repeat, (text == || text.length() == 0 || searchList == || searchList.length == 0 || replacementList == || replacementList.length == 0 (timeToLive < 0 IllegalStateException("TimeToLive of " + timeToLive + " is less than 0: " + searchLength = replacementLength = (searchLength != IllegalArgumentException("Search and Replace array lengths don't match: " + + " vs " + [] noMoreMatchesForReplIndex = textIndex = -1 replaceIndex = -1 tempIndex = -1 ( i = 0; i < searchLength; i++ (noMoreMatchesForReplIndex[i] || searchList[i] == || searchList[i].length() == 0 || replacementList[i] == tempIndex = (tempIndex == -1 noMoreMatchesForReplIndex[i] = } (textIndex == -1 || tempIndex < textIndex = replaceIndex = (textIndex == -1 start = 0 increase = 0 ( i = 0; i < searchList.length; i++ (searchList[i] == || replacementList[i] == greater = replacementList[i].length() - (greater > 0 increase += 3 * greater; increase = Math.min(increase,text.length() / 5 StrBuilder buf = StrBuilder(text.length() + (textIndex != -1 ( i = start; i < textIndex; i++ start = textIndex + textIndex = -1 replaceIndex = -1 tempIndex = -1 ( i = 0; i < searchLength; i++ (noMoreMatchesForReplIndex[i] || searchList[i] == || searchList[i].length() == 0 || replacementList[i] == tempIndex = (tempIndex == -1 noMoreMatchesForReplIndex[i] = } (textIndex == -1 || tempIndex < textIndex = replaceIndex = textLength = ( i = start; i < textLength; i++ String result = (! replaceEach(result,repeat,timeToLive - 1 Replaces all occurrences of a character in a String with another. A null string input returns null. null if null string input String replaceChars(String str, (str == Replaces multiple characters in a String in one go. For example:
replaceChars(&quot;hello&quot;,&quot;ho&quot;,&quot;jy&quot;) = jelly.

A null string input returns null. The length of the search characters should normally equal the length null if null string input (isEmpty(str) || (replaceChars == replaceChars = modified = replaceCharsLength = strLength = StrBuilder buf = ( i = 0; i < strLength; i++ ch = index = (index >= 0 modified = (index < } Overlays part of a String with another String.

null if null String input String overlayString(String text,String overlay, StrBuilder(start + overlay.length() + text.length() - end + 1 .append(text.substring(0 Overlays part of a String with another String.

A null string input returns null. null if null String input String overlay(String str, (str == (overlay == overlay = len = (start < 0 start = 0 (start > start = (end < 0 end = 0 (end > end = (start > temp = start = end = StrBuilder(len + start - end + overlay.length() + 1 .append(str.substring(0 Removes one newline from end of a String if it's there, n&quot;, r&quot;,or &quot;rn&quot;.

NOTE: This method changed in 2.0. null if null String input (str.length() == 1 ch = str.charAt(0 (ch == CharUtils.CR || ch == lastIdx = str.length() - 1 last = (last == (str.charAt(lastIdx - 1) == lastIdx-- } (last != lastIdx++ str.substring(0 Removes separator from the end of str if it's there,otherwise leave it alone.

NOTE: This method changed in version 2.0. null if null String input (isEmpty(str) || separator == str.substring(0,str.length() - Remove any &quot;n&quot; if and only if it is at the end null chompLast(str,"n" Remove a value if and only if the String ends with that value.

null (str.length() == 0 String sub = str.substring(str.length() - str.substring(0,str.length() - Remove everything and return the last value of a supplied String,and null idx = (idx == str.length() - } (idx != -1 } Remove the first value of a supplied String,and everything before it null idx = (idx == -1 str.substring(idx + Remove and return everything before the first value of a null idx = (idx == -1 str.substring(0,idx + Remove the last character from a String.

If the String ends in rn,then remove both null if null String input (str == strLen = (strLen < 2 lastIdx = strLen - 1 String ret = str.substring(0 last = (last == (ret.charAt(lastIdx - 1) == ret.substring(0,lastIdx - 1 Removes n from end of a String if it's there. r precedes it,then remove that too.

null lastIdx = str.length() - 1 (lastIdx <= 0 last = (last == (str.charAt(lastIdx - 1) == lastIdx-- } lastIdx++ str.substring(0 Escapes any values it finds into their String form.

So a tab becomes the characters '' and 't'.

As of Lang 2.0,this calls { null Repeat a String repeat times to form a null if null String input String repeat(String str, (str == (repeat <= 0 inputLength = (repeat == 1 || inputLength == 0 (inputLength == 1 && repeat <= padding(repeat,str.charAt(0 outputLength = inputLength * 1 ch = str.charAt(0 [] output1 = ( i = repeat - 1; i >= 0; i-- output1[i] = 2 ch0 = str.charAt(0 ch1 = str.charAt(1 [] output2 = ( i = repeat * 2 - 2; i >= 0; i--,i-- output2[i] = output2[i + 1] = StrBuilder buf = ( i = 0; i < repeat; i++ Repeat a String repeat times to form a null if null String input String repeat(String str, (str == || separator == } String result = repeat(str + Returns padding using the specified delimiter repeated Note: this method doesn't not support padding with chars to be represented. repeat &lt; 0 String padding( repeat, padChar) (repeat < 0 IndexOutOfBoundsException("Cannot pad a negative amount: " + [] buf = ( i = 0; i < buf.length; i++ buf[i] = Right pad a String with spaces (' ').

The String is padded to the size of size.

null if null String input String rightPad(String str, rightPad(str,size,' ' Right pad a String with a specified character.

The String is padded to the size of size.

null if null String input String rightPad(String str, size, (str == pads = size - (pads <= 0 str; (pads > Right pad a String with a specified String.

The String is padded to the size of size.

null if null String input String rightPad(String str, (str == padStr = " " padLen = strLen = pads = size - (pads <= 0 str; (padLen == 1 && pads <= rightPad(str,padStr.charAt(0 (pads == } (pads < str.concat(padStr.substring(0 } [] padding = [] padChars = ( i = 0; i < pads; i++ padding[i] = padChars[i % str.concat( Left pad a String with spaces (' ').

The String is padded to the size of size.

null if null String input String leftPad(String str, leftPad(str,' ' Left pad a String with a specified character.

Pad to a size of size.

null if null String input String leftPad(String str, (str == pads = size - (pads <= 0 str; (pads > Left pad a String with a specified String.

Pad to a size of size.

null if null String input String leftPad(String str,String padStr) { (str == padStr = " " padLen = strLen = pads = size - (pads <= 0 str; (padLen == 1 && pads <= leftPad(str,padStr.charAt(0 (pads == } (pads < padStr.substring(0 } [] padding = [] padChars = ( i = 0; i < pads; i++ padding[i] = padChars[i % 0 if the String is null. null 0 if the String is null. str == ? 0 Centers a String in a larger String of size size If the size is less than the String length,the String is returned. null String returns null. Equivalent to center(str," ").

null if null String input String center(String str, center(str,' ' Centers a String in a larger String of size size. If the size is less than the String length,the String is returned. null String returns null. null if null String input String center(String str, (str == || size <= 0 strLen = pads = size - (pads <= 0 str = leftPad(str,strLen + pads / 2 str = Centers a String in a larger String of size size. If the size is less than the String length,the String is returned. null String returns null. null if null String input null or empty String center(String str,String padStr) { (str == || size <= 0 padStr = " " strLen = pads = size - (pads <= 0 str = leftPad(str,padStr); str = Converts a String to upper case as per { A null input String returns null.

Note: As described in the documentation for { null if null String input (str == Converts a String to upper case as per { A null input String returns null.

null if null String input (str == Converts a String to lower case as per { A null input String returns null.

Note: As described in the documentation for { null if null String input (str == Converts a String to lower case as per { A null input String returns null.

null if null String input (str == Capitalizes a String changing the first letter to title case as For a word based algorithm,see { null input String returns null.

null if null String input (str == || (strLen = str.length()) == 0 .append(Character.toTitleCase(str.charAt(0 .append(str.substring(1 Capitalizes a String changing the first letter to title case as null if null String input Uncapitalizes a String changing the first letter to title case as For a word based algorithm,see { null input String returns null.

null if null String input (str == || (strLen = str.length()) == 0 .append(Character.toLowerCase(str.charAt(0 .append(str.substring(1 Uncapitalizes a String changing the first letter to title case as null if null String input Swaps the case of a String changing upper and title case to Upper case character converts to Lower case Title case character converts to Lower case Lower case character converts to Upper case For a word based algorithm,see { null input String returns null.

NOTE: This method changed in Lang version 2.0. null if null String input (str == || (strLen = str.length()) == 0 StrBuilder buffer = ch = 0 ( i = 0; i < strLen; i++ ch = ch = } ch = } ch = Capitalizes all the whitespace separated words in a String. Whitespace is defined by { null input String returns null.

null if null String input Counts how many times the substring appears in the larger String.

A null or empty ("") String input returns 0.

null (isEmpty(str) || 0 count = 0 idx = 0 ((idx = str.indexOf(sub,idx)) != count++ idx += Checks if the String contains only unicode letters.

null will return false. true.

true if only contains letters,and is non-null (str == sz = ( i = 0; i < sz; i++ (Character.isLetter(str.charAt(i)) == Checks if the String contains only unicode letters and null will return false true.

true if only contains letters and space, (str == sz = ( i = 0; i < sz; i++ ((Character.isLetter(str.charAt(i)) == ) && (str.charAt(i) != ' ' Checks if the String contains only unicode letters or digits.

null will return false. true.

true if only contains letters or digits, (str == sz = ( i = 0; i < sz; i++ (Character.isLetterOrDigit(str.charAt(i)) == Checks if the String contains only unicode letters,digits ' ').

null will return false. true.

true if only contains letters,digits or space, (str == sz = ( i = 0; i < sz; i++ ((Character.isLetterOrDigit(str.charAt(i)) == ) && (str.charAt(i) != ' ' Checks if the string contains only ASCII printable characters.

null will return false. true.

true if every character is in the range (str == sz = ( i = 0; i < sz; i++ (CharUtils.isAsciiPrintable(str.charAt(i)) == Checks if the String contains only unicode digits. null will return false. true.

true if only contains digits,and is non-null (str == sz = ( i = 0; i < sz; i++ (Character.isDigit(str.charAt(i)) == Checks if the String contains only unicode digits or space ' '). null will return false. true.

true if only contains digits or space, (str == sz = ( i = 0; i < sz; i++ ((Character.isDigit(str.charAt(i)) == ) && (str.charAt(i) != ' ' Checks if the String contains only whitespace.

null will return false. true.

true if only contains whitespace,and is non-null (str == sz = ( i = 0; i < sz; i++ ((Character.isWhitespace(str.charAt(i)) == Checks if the String contains only lowercase characters.

null will return false. false.

true if only contains lowercase characters,and is non-null (str == || sz = ( i = 0; i < sz; i++ (Character.isLowerCase(str.charAt(i)) == Checks if the String contains only uppercase characters.

null will return false. false.

true if only contains uppercase characters,and is non-null (str == || sz = ( i = 0; i < sz; i++ (Character.isUpperCase(str.charAt(i)) == Returns either the passed in String, null,an empty String ("").

null str == ? Returns either the passed in String,or if the String is null,the value of defaultStr.

null,may be null null str == ? Returns either the passed in String,or if the String is null,the value of defaultStr.

StringUtils.isBlank(str) ? Returns either the passed in String,or if the String is null,the value of defaultStr.

null,may be null StringUtils.isEmpty(str) ? Reverses a String as per { A null String returns null.

null if null String input (str == Reverses a String that is delimited by a specific character.

The Strings between the delimiters are not reversed. '.').

null if null String input String reverseDelimited(String str, (str == String[] strs = Reverses a String that is delimited by a specific character.

The Strings between the delimiters are not reversed. ".").

null if null String input (str == String[] strs = (separatorChars == join(strs,' ' Abbreviates a String using ellipses. This will turn Specifically: If str is less than maxWidth characters Else abbreviate it to (substring(str,max-3) + "..."). If maxWidth is less than 4,throw an IllegalArgumentException. In no case will it return a String of length greater than maxWidth. null if null String input String abbreviate(String str, abbreviate(str,maxWidth); Abbreviates a String using ellipses. This will turn Works like abbreviate(String,int),but allows you to specify In no case will it return a String of length greater than maxWidth.

null if null String input String abbreviate(String str, offset, (str == (maxWidth < 4 IllegalArgumentException("Minimum abbreviation width is 4" (str.length() <= (offset > offset = ((str.length() - offset) < (maxWidth - 3 offset = str.length() - (maxWidth - 3 (offset <= 4 str.substring(0,maxWidth - 3) + "..." (maxWidth < 7 IllegalArgumentException("Minimum abbreviation width with offset is 7" ((offset + (maxWidth - 3)) < "..." + abbreviate(str.substring(offset),maxWidth - 3 "..." + str.substring(str.length() - (maxWidth - 3 Abbreviates a String to the length passed,replacing the middle characters with the supplied This abbreviation only occurs if the following criteria is met: Neither the String for abbreviation nor the replacement String are null or empty The length to truncate to is less than the length of the supplied String The length to truncate to is greater than 0 The abbreviated String will have enough room for the length supplied replacement String str to. String abbreviateMiddle(String str,String middle, (isEmpty(str) || (length >= str.length() || length < (middle.length()+2 targetSting = length- startOffset = targetSting/2+targetSting%2 endOffset = str.length()-targetSting/2 StrBuilder builder = builder.append(str.substring(0 Compares two Strings,and returns the portion where they differ. For example, difference("i am a machine","i am a robot") -> "robot".

(str1 == (str2 == at = (at == Compares two Strings,and returns the index at which the For example, indexOfDifference("i am a machine","i am a robot") -> 7

(str1 == (str1 == || str2 == 0 (i = 0; i < str1.length() && i < str2.length(); ++ (str1.charAt(i) != (i < str2.length() || i < Compares all Strings in an array and returns the index at which the For example, indexOfDifference(new String[] {"i am a machine","i am a robot"}) -> 7

(strs == || strs.length <= 1 anyStringNull = allStringsNull = arrayLen = shortestStrLen = longestStrLen = 0 ( i = 0; i < arrayLen; i++ (strs[i] == anyStringNull = shortestStrLen = 0 } allStringsNull = shortestStrLen = longestStrLen = (allStringsNull || (longestStrLen == 0 && ! (shortestStrLen == 0 0 firstDiff = -1 ( stringPos = 0; stringPos < shortestStrLen; stringPos++ comparisonChar = strs[0 ( arrayPos = 1; arrayPos < arrayLen; arrayPos++ (strs[arrayPos].charAt(stringPos) != firstDiff = (firstDiff != -1 (firstDiff == -1 && shortestStrLen != Compares all Strings in an array and returns the initial sequence of For example, getCommonPrefix(new String[] {"i am a machine","i am a robot"}) -> "i am a "

(strs == || strs.length == 0 smallestIndexOfDiff = (smallestIndexOfDiff == (strs[0] == strs[0 } (smallestIndexOfDiff == 0 } strs[0].substring(0 Find the Levenshtein distance between two Strings.

This is the number of changes needed to change one String into The previous implementation of the Levenshtein distance algorithm Chas Emerick has written an implementation in Java,which avoids an OutOfMemoryError null (s == || t == IllegalArgumentException("Strings must not be null" n = s.length(); m = t.length(); (n == 0 } (m == 0 (n > String tmp = s = t = n = m = p[] = [n+1]; d[] = [n+1]; _d[]; i; j; t_j; cost; (i = 0; i<=n; i++ p[i] = (j = 1; j<=m; j++ t_j = t.charAt(j-1 d[0] = (i=1; i<=n; i++ cost = s.charAt(i-1)==t_j ? 0 : 1 d[i] = Math.min(Math.min(d[i-1]+1,p[i]+1),p[i-1]+ _d = p = d = Check if a String starts with a specified prefix.

nulls are handled without exceptions. Two null true if the String starts with the prefix,or null startsWith(str,prefix, Case insensitive check if a String starts with a specified prefix.

nulls are handled without exceptions. Two null true if the String starts with the prefix,or null startsWith(str, Check if a String starts with a specified prefix (optionally case insensitive).

true if the String starts with the prefix or null startsWith(String str,String prefix, (str == || prefix == (str == && prefix == (prefix.length() > str.regionMatches(ignoreCase,prefix.length()); Check if a String starts with any of an array of specified strings.

true if the String starts with any of the the prefixes,or null (isEmpty(string) || ( i = 0; i < searchStrings.length; i++ String searchString = Check if a String ends with a specified suffix.

nulls are handled without exceptions. Two null true if the String ends with the suffix,or null endsWith(str,suffix, Case insensitive check if a String ends with a specified suffix.

nulls are handled without exceptions. Two null true if the String ends with the suffix,or null endsWith(str, Check if a String ends with a specified suffix (optionally case insensitive).

true if the String starts with the prefix or null endsWith(String str,String suffix, (str == || suffix == (str == && suffix == (suffix.length() > strOffset = str.length() - str.regionMatches(ignoreCase,strOffset,suffix.length()); { to remove leading and trailing whitespace { removes control characters (char &lt;= 32) from both null if null String input str = (str == || str.length() <= 2 StrBuilder b = ( i = 0; i < str.length(); i++ c = (i > 0 && !Character.isWhitespace(str.charAt(i - 1 b.append(' ' } Check if a String ends with any of an array of specified strings.

true if the String ends with any of the the prefixes,or null (isEmpty(string) || ( i = 0; i < searchStrings.length; i++ String searchString = }

这里提供:

                        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读