Class StringUtil
- Author:
- Brian Wing Shun Chan, Sandeep Soni, Ganesh Ram, Shuyang Zhou, Hugo Huijser
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringAdds stringaddto stringsresulting in a comma delimited list of strings, disallowing duplicate strings in the list.static StringAdds stringaddto stringsthat represents a delimited list of strings, using a specified delimiter and disallowing duplicate words.static StringAdds stringaddto stringsthat represents a delimited list of strings, using a specified delimiter and optionally allowing duplicate words.static StringappendParentheticalSuffix(String s, int suffix) Returns the original string with an appended space followed by the string value of the suffix surrounded by parentheses.static StringappendParentheticalSuffix(String s, String suffix) Returns the original string with an appended space followed by the suffix surrounded by parentheses.static StringbytesToHexString(byte[] bytes) Converts an array of bytes to a string representing the bytes in hexadecimal form.static booleanReturnstrueif the string contains the text as one or more consecutive comma delimited list entries.static booleanReturnstrueif the string contains the text as one or more consecutive delimited list entries.static booleancontainsIgnoreCase(String s, String text) Returnstrueif the string contains the text as one or more consecutive comma delimited list entries, ignoring case.static booleancontainsIgnoreCase(String s, String text, String delimiter) Returnstrueif the string contains the text as one or more consecutive delimited list entries, ignoring case.static intstatic intstatic intstatic intReturns the number of times the text appears in the string.static booleanReturnstrueif the string ends with the specified character, ignoring case.static booleanReturnstrueif the string ends with the stringend, ignoring case.static booleanReturnstrueif the strings are equal.static booleanequalsIgnoreBreakLine(String s1, String s2) Returnstrueif the strings are equal, ignoring new line characters.static booleanequalsIgnoreCase(char c1, char c2) static booleanequalsIgnoreCase(String s1, String s2) Returnstrueif the strings are equal, ignoring case.static StringReturns the substring of English characters from the string.static StringReturns a string consisting of all of the digits extracted from the string.static StringextractFirst(String s, char delimiter) Returns the substring ofsup to but not including the first occurrence of the delimiter.static StringextractFirst(String s, String delimiter) Returns the substring ofsup to but not including the first occurrence of the delimiter.static StringextractLast(String s, char delimiter) Returns the substring ofsafter but not including the last occurrence of the delimiter.static StringextractLast(String s, String delimiter) Returns the substring ofsafter but not including the last occurrence of the delimiter.static StringReturns the substring of all leading digits of strings, or an empty string if it has no leading digits.static StringgetTitleCase(String s, boolean allowDash, String... exceptions) static byte[]hexStringToBytes(String hexString) static intindexOfAny(String s, char[] chars) Returns the index within the string of the first occurrence of any character from the array.static intindexOfAny(String s, char[] chars, int fromIndex) Returns the index within the string of the first occurrence of any character from the array, starting the search at the specified index within the string.static intindexOfAny(String s, char[] chars, int fromIndex, int toIndex) Returns the index within the string of the first occurrence of any character from the array, up to and including the specified end index within the string, starting the search at the specified start index within the string.static intindexOfAny(String s, String[] texts) Returns the index within the string of the first occurrence of any string from the array.static intindexOfAny(String s, String[] texts, int fromIndex) Returns the index within the string of the first occurrence of any string from the array, starting the search at the specified index within the string.static intindexOfAny(String s, String[] texts, int fromIndex, int toIndex) Returns the index within the string of the first occurrence of any string from the array, up to and including the specified end index within the string, starting the search at the specified start index within the string.static StringInserts one string into the other at the specified offset index.static booleanReturnstrueif all the characters in stringsare lower case, ignoring any non-alphabetic characters.static booleanReturnstrueif all the characters in stringsare upper case, ignoring any non-alphabetic characters.static intlastIndexOfAny(String s, char[] chars) Returns the index within the string of the last occurrence of any character from the array.static intlastIndexOfAny(String s, char[] chars, int toIndex) Returns the index within the string of the last occurrence of any character from the array, starting the search at the specified index within the string.static intlastIndexOfAny(String s, char[] chars, int fromIndex, int toIndex) Returns the index within the string of the last occurrence of any character from the array, up to and including the specified end index within the string, starting the search at the specified start index within the string.static intlastIndexOfAny(String s, String[] texts) Returns the index within the string of the last occurrence of any string from the array.static intlastIndexOfAny(String s, String[] texts, int toIndex) Returns the index within the string of the last occurrence of any string from the array, starting the search at the specified index within the string.static intlastIndexOfAny(String s, String[] texts, int fromIndex, int toIndex) Returns the index within the string of the last occurrence of any string from the array, up to and including the specified end index within the string, starting the search at the specified start index within the string.static StringConverts all of the characters in the string to lower case.static voidConverts all of the characters in the arbitrary number of strings to lower case.static StringConverts the first character of the string to lower case.static booleanReturnstrueif the specified pattern occurs at any position in the string.static booleanmatchesIgnoreCase(String s, String pattern) Returnstrueif the specified pattern occurs at any position in the string, ignoring case.static Stringmerge(boolean[] array) Merges the elements of the boolean array into a string representing a comma delimited list of its values.static StringMerges the elements of the boolean array into a string representing a delimited list of its values.static Stringmerge(char[] array) Merges the elements of the character array into a string representing a comma delimited list of its values.static StringMerges the elements of the character array into a string representing a delimited list of its values.static Stringmerge(double[] array) Merges the elements of an array of double-precision decimal numbers by returning a string representing a comma delimited list of its values.static StringMerges the elements of an array of double-precision decimal numbers by returning a string representing a delimited list of its values.static Stringmerge(float[] array) Merges the elements of an array of decimal numbers into a string representing a comma delimited list of its values.static StringMerges the elements of an array of decimal numbers into a string representing a delimited list of its values.static Stringmerge(int[] array) Merges the elements of an array of integers into a string representing a comma delimited list of its values.static StringMerges the elements of an array of integers into a string representing a delimited list of its values.static Stringmerge(long[] array) Merges the elements of an array of long integers by returning a string representing a comma delimited list of its values.static StringMerges the elements of an array of long integers by returning a string representing a delimited list of its values.static Stringmerge(short[] array) Merges the elements of an array of short integers by returning a string representing a comma delimited list of its values.static StringMerges the elements of an array of short integers by returning a string representing a delimited list of its values.static StringMerges the elements of an array of objects into a string representing a comma delimited list of the objects.static StringMerges the elements of an array of objects into a string representing a delimited list of the objects.static Stringmerge(Collection<?> collection) Merges the elements of the collection by returning a string representing a comma delimited list of its values.static Stringmerge(Collection<?> collection, String delimiter) Merges the elements of the collection by returning a string representing a delimited list of its values.static StringReturns the string enclosed by apostrophes.static StringReturns the string enclosed by the quote character.static StringReturns the string enclosed by the quote strings.static StringrandomId()Returns a randomized string of four lower case, alphabetic characters.static StringrandomId(int length) Returns a randomized string with the length informed and only alphabetic characters.static StringReturns a randomized string of eight characters consisting of lower case letters, upper case letters, and single-digit whole numbers.static StringrandomString(int length) Returns a randomized string of the specified length consisting of lower case letters, upper case letters, and single-digit whole numbers.static Stringread(InputStream inputStream) static Stringstatic Stringread(ClassLoader classLoader, String name) static Stringread(ClassLoader classLoader, String name, boolean all) static voidreadLines(InputStream inputStream, Collection<String> lines) static StringremoveChar(String s, char oldSub) static StringremoveChars(String s, char... oldSubs) static StringremoveFirst(String s, String oldSub) static StringremoveFromList(String s, String element) Removes theremovestring from stringsthat represents a list of comma delimited strings.static StringremoveFromList(String s, String element, String delimiter) Removes theremovestring from stringsthat represents a list of delimited strings.static StringremoveLast(String s, String oldSub) static StringremoveSubstring(String s, String oldSub) static StringremoveSubstrings(String s, String... oldSubs) static Stringstatic Stringstatic StringReplaces all occurrences of the character with the new character.static StringReplaces all occurrences of the character with the new string.static Stringstatic StringReplaces all occurrences of the elements of the string array with the corresponding elements of the new string array.static StringReplaces all occurrences of the elements of the string array with the corresponding elements of the new string array, optionally replacing only substrings that are surrounded by word boundaries.static StringReplaces all occurrences of the string with the new string.static StringReplaces all occurrences of the string with the new string, starting from the specified index.static StringReplaces all occurrences of the keywords found in the substring, defined by the beginning and ending strings, with the new values.static StringreplaceFirst(String s, char oldSub, char newSub) Replaces the first occurrence of the character with the new character.static StringreplaceFirst(String s, char oldSub, String newSub) Replaces the first occurrence of the character with the new string.static StringreplaceFirst(String s, String[] oldSubs, String[] newSubs) Replaces the first occurrences of the elements of the string array with the corresponding elements of the new string array.static StringreplaceFirst(String s, String oldSub, String newSub) Replaces the first occurrence of the string with the new string.static StringreplaceFirst(String s, String oldSub, String newSub, int fromIndex) Replaces the first occurrences of the elements of the string array with the corresponding elements of the new string array, beginning the element search from the index position.static StringreplaceLast(String s, char oldSub, char newSub) Replaces the last occurrence of the character with the new character.static StringreplaceLast(String s, char oldSub, String newSub) Replaces the last occurrence of the character with the new string.static StringreplaceLast(String s, String[] oldSubs, String[] newSubs) Replaces the last occurrences of the elements of the string array with the corresponding elements of the new string array.static StringreplaceLast(String s, String oldSub, String newSub) Replaces the last occurrence of the stringoldSubin the stringswith the stringnewSub.static com.liferay.petra.string.StringBundlerReplaces all occurrences of the keywords found in the substring, defined by the beginning and ending strings, with the new values.static com.liferay.petra.string.StringBundlerreplaceWithStringBundler(String s, String begin, String end, Map<String, com.liferay.petra.string.StringBundler> values) Replaces all occurrences of the keywords found in the substring, defined by the beginning and ending strings, with the new values.static StringReturns a string representing the original string appended with suffix "..." and then shortened to 20 characters.static StringReturns a string representing the original string appended with suffix "..." and then shortened to the specified length.static StringReturns a string representing the original string appended with the specified suffix and then shortened to the specified length.static StringReturns a string representing the original string appended with the specified suffix and then shortened to 20 characters.static String[]Splits stringsaround comma characters.static boolean[]Splits the stringsaround comma characters returning the boolean values of the substrings.static String[]Splits the stringsaround the specified delimiter.static double[]Splits the stringsaround comma characters returning the double-precision decimal values of the substrings.static float[]Splits the stringsaround comma characters returning the decimal values of the substrings.static int[]Splits the stringsaround comma characters returning the integer values of the substrings.static long[]Splits the stringsaround comma characters returning the long integer values of the substrings.static short[]Splits the stringsaround comma characters returning the short integer values of the substrings.static String[]Splits the stringsaround the specified delimiter string.static boolean[]Splits the stringsaround the specified delimiter returning the boolean values of the substrings.static double[]Splits the stringsaround the specified delimiter returning the double-precision decimal values of the substrings.static float[]Splits the stringsaround the specified delimiter returning the decimal values of the substrings.static int[]Splits the stringsaround the specified delimiter returning the integer values of the substrings.static long[]Splits the stringsaround the specified delimiter returning the long integer values of the substrings.static short[]Splits the stringsaround the specified delimiter returning the short integer values of the substrings.static String[]splitLines(String s) Splits stringsaround return and newline characters.static booleanstartsWith(String s, char begin) Returnstrueif, ignoring case, the string starts with the specified character.static booleanstartsWith(String s, String start) Returnstrueif, ignoring case, the string starts with the specified start string.static intstartsWithWeight(String s1, String s2) Returns the number of starting characters thats1ands2have in common before their characters deviate.static StringstripBetween(String s, String begin, String end) Returns a string representing the combination of the substring ofsup to but not including the stringbeginconcatenated with the substring ofsafter but not including the stringend.static StringstripCDATA(String s) Returns a string representing the stringswith its<!static StringReturns a string representing the stringswithout an appended parenthetical suffix.static StringtoCharCode(String s) Returns a string representing the Unicode character codes of the characters comprising the strings.static StringtoHexString(int i) Returns a string representing the hexidecimal character code of the integer.static StringtoHexString(long l) Returns a string representing the hexidecimal character code of the long integer.static StringtoHexString(Object object) Returns a string representing the hexidecimal character code of theIntegerorLongobject type.static StringConverts all of the characters in the string to lower case, based on the portal instance's default locale.static StringtoLowerCase(String s, Locale locale) Converts all of the characters in the string to lower case, based on the locale.static StringConverts all of the characters in the string to upper case, based on the portal instance's default locale.static StringtoUpperCase(String s, Locale locale) Converts all of the characters in the string to upper case, based on the locale.static StringTrims all leading and trailing whitespace from the string.static StringTrims leading and trailing whitespace from the string, up to but not including the whitespace character specified byc.static StringTrims leading and trailing whitespace from the string, up to but not including the whitespace characters specified byexceptions.static StringTrims all leading whitespace from the string.static StringtrimLeading(String s, char c) Trims leading whitespace from the string, up to but not including the whitespace character specified byc.static StringtrimLeading(String s, char[] exceptions) Trims leading whitespace from the string, up to but not including the whitespace characters specified byexceptions.static StringTrims all trailing whitespace from the string.static StringtrimTrailing(String s, char c) Trims trailing whitespace from the string, up to but not including the whitespace character specified byc.static StringtrimTrailing(String s, char[] exceptions) Trims trailing whitespace from the string, up to but not including the whitespace characters specified byexceptions.static StringRemoves leading and trailing double and single quotation marks from the string.static StringConverts all of the characters in the string to upper case.static StringConverts the first character of the string to upper case.static booleanwildcardMatches(String s, String wildcard, char singleWildcardCharacter, char multipleWildcardCharacter, char escapeWildcardCharacter, boolean caseSensitive) Returnstrueif the string matches the wildcard pattern.
-
Field Details
-
HEX_DIGITS
protected static final char[] HEX_DIGITS
-
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
add
Adds stringaddto stringsresulting in a comma delimited list of strings, disallowing duplicate strings in the list.The resulting string ends with a comma even if the original string does not.
- Parameters:
s- the original string, representing a comma delimited list of stringsadd- the string to add to the original, representing the string to add to the list- Returns:
- a string that represents the original string and the added string
separated by a comma, or
nullif the string to add isnull
-
add
Adds stringaddto stringsthat represents a delimited list of strings, using a specified delimiter and disallowing duplicate words.The returned string ends with the delimiter even if the original string does not.
- Parameters:
s- the original string, representing a delimited list of stringsadd- the string to add to the original, representing the string to add to the listdelimiter- the delimiter used to separate strings in the list- Returns:
- a string that represents the original string and the added string
separated by the delimiter, or
nullif the string to add or the delimiter string isnull
-
add
Adds stringaddto stringsthat represents a delimited list of strings, using a specified delimiter and optionally allowing duplicate words.The returned string ends with the delimiter even if the original string does not.
- Parameters:
s- the original string, representing a delimited list of stringsadd- the string to add to the original, representing the string to add to the listdelimiter- the delimiter used to separate strings in the listallowDuplicates- whether to allow duplicate strings- Returns:
- a string that represents the original string and the added string
separated by the delimiter, or
nullif the string to add or the delimiter string isnull
-
appendParentheticalSuffix
Returns the original string with an appended space followed by the string value of the suffix surrounded by parentheses.If the original string ends with a numerical parenthetical suffix having an integer value equal to
suffix - 1, then the existing parenthetical suffix is replaced by the new one.Examples:
appendParentheticalSuffix("file", 0) returns "file (0)" appendParentheticalSuffix("file (0)", 0) returns "file (0) (0)" appendParentheticalSuffix("file (0)", 1) returns "file (1)" appendParentheticalSuffix("file (0)", 2) returns "file (0) (2)"- Parameters:
s- the original stringsuffix- the suffix to be appended- Returns:
- the resultant string whose characters equal those of the original string, followed by a space, followed by the specified suffix enclosed in parentheses, or, if the difference between the provided suffix and the existing suffix is 1, the existing suffix is incremented by 1
-
appendParentheticalSuffix
Returns the original string with an appended space followed by the suffix surrounded by parentheses.Example:
appendParentheticalSuffix("Java", "EE") returns "Java (EE)"- Parameters:
s- the original stringsuffix- the suffix to be appended- Returns:
- a string that represents the original string, followed by a space, followed by the suffix enclosed in parentheses
-
asList
-
bytesToHexString
Converts an array of bytes to a string representing the bytes in hexadecimal form.- Parameters:
bytes- the array of bytes to be converted- Returns:
- the string representing the bytes in hexadecimal form
-
contains
Returnstrueif the string contains the text as one or more consecutive comma delimited list entries.Examples:
contains("one,two,three", "two") returns true contains("one,two,three", "thr") returns false contains("one,two,three", "one,two") returns true- Parameters:
s- the string in which to searchtext- the text to search for in the string- Returns:
trueif the string contains the text as one or more consecutive comma delimited list entries;falseotherwise
-
contains
Returnstrueif the string contains the text as one or more consecutive delimited list entries.Examples:
contains("three...two...one", "two", "...") returns true contains("three...two...one", "thr", "...") returns false contains("three...two...one", "two...one", "...") returns true- Parameters:
s- the string in which to searchtext- the text to search for in the stringdelimiter- the delimiter- Returns:
trueif the string contains the text as one or more consecutive delimited list entries;falseotherwise
-
containsIgnoreCase
Returnstrueif the string contains the text as one or more consecutive comma delimited list entries, ignoring case.Examples:
containsIgnoreCase("one,two,three", "Two") returns true containsIgnoreCase("one,two,three", "thr") returns false containsIgnoreCase("one,two,three", "one,two") returns true- Parameters:
s- the string in which to searchtext- the text to search for in the string- Returns:
trueif the string contains the text as one or more consecutive comma delimited list entries;falseotherwise
-
containsIgnoreCase
Returnstrueif the string contains the text as one or more consecutive delimited list entries, ignoring case.Examples:
containsIgnoreCase("three...two...one", "Two", "...") returns true containsIgnoreCase("three...two...one", "thr", "...") returns false containsIgnoreCase("three...two...one", "two...one", "...") returns true- Parameters:
s- the string in which to searchtext- the text to search for in the stringdelimiter- the delimiter- Returns:
trueif the string contains the text as one or more consecutive delimited list entries;falseotherwise
-
count
-
count
-
count
-
count
Returns the number of times the text appears in the string.- Parameters:
s- the string in which to searchtext- the text to search for in the string- Returns:
- the number of times the text appears in the string
-
endsWith
Returnstrueif the string ends with the specified character, ignoring case.- Parameters:
s- the string in which to searchend- the character to search for at the end of the string- Returns:
trueif the string ends with the specified character, ignoring case;falseotherwise
-
endsWith
Returnstrueif the string ends with the stringend, ignoring case.- Parameters:
s- the string in which to searchend- the string to check for at the end of the string- Returns:
trueif the string ends with the stringend, ignoring case;falseotherwise
-
equals
Returnstrueif the strings are equal.- Parameters:
s1- the first string to compares2- the second string to compare- Returns:
trueif the strings are equal;falseotherwise
-
equalsIgnoreBreakLine
Returnstrueif the strings are equal, ignoring new line characters.- Parameters:
s1- the first string to compares2- the second string to compare- Returns:
trueif the strings are equal, ignoring new line characters;falseotherwise
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(char c1, char c2) -
equalsIgnoreCase
Returnstrueif the strings are equal, ignoring case.- Parameters:
s1- the first string to compares2- the second string to compare- Returns:
trueif the strings are equal, ignoring case;falseotherwise
-
extractChars
Returns the substring of English characters from the string.- Parameters:
s- the string from which to extract characters- Returns:
- the substring of English characters from the string, or an empty
string if the given string is
null
-
extractDigits
Returns a string consisting of all of the digits extracted from the string.- Parameters:
s- the string from which to extract digits- Returns:
- a string consisting of all of the digits extracted from the string
-
extractFirst
Returns the substring ofsup to but not including the first occurrence of the delimiter.- Parameters:
s- the string from which to extract a substringdelimiter- the character whose index in the string marks where to end the substring- Returns:
- the substring of
sup to but not including the first occurrence of the delimiter,nullif the string isnullor the delimiter does not occur in the string
-
extractFirst
Returns the substring ofsup to but not including the first occurrence of the delimiter.- Parameters:
s- the string from which to extract a substringdelimiter- the smaller string whose index in the larger string marks where to end the substring- Returns:
- the substring of
sup to but not including the first occurrence of the delimiter,nullif the string isnullor the delimiter does not occur in the string
-
extractLast
Returns the substring ofsafter but not including the last occurrence of the delimiter.- Parameters:
s- the string from which to extract the substringdelimiter- the character whose last index in the string marks where to begin the substring- Returns:
- the substring of
safter but not including the last occurrence of the delimiter,nullif the string isnullor the delimiter does not occur in the string
-
extractLast
Returns the substring ofsafter but not including the last occurrence of the delimiter.- Parameters:
s- the string from which to extract the substringdelimiter- the string whose last index in the string marks where to begin the substring- Returns:
- the substring of
safter but not including the last occurrence of the delimiter,nullif the string isnullor the delimiter does not occur in the string
-
extractLeadingDigits
Returns the substring of all leading digits of strings, or an empty string if it has no leading digits.- Parameters:
s- the string from which to extract the substring- Returns:
- the substring of all leading digits of string
s, or an empty string if it has no leading digits
-
getTitleCase
-
hexStringToBytes
-
indexOfAny
Returns the index within the string of the first occurrence of any character from the array.A
nullstring returns-1. Anullor empty array returns-1.Examples:
indexOfAny(null, *) returns -1 indexOfAny(*, null) returns -1 indexOfAny(*, []) returns -1 indexOfAny("zzabyycdxx", ['a','c']) returns 2 indexOfAny("zzabyycdxx", ['c','a']) returns 2 indexOfAny("zzabyycdxx", ['m','n']) returns -1- Parameters:
s- the string to search (optionallynull)chars- the characters to search for (optionallynull)- Returns:
- the index within the string of the first occurrence of any
character from the array, or
-1if none of the characters occur
-
indexOfAny
Returns the index within the string of the first occurrence of any character from the array, starting the search at the specified index within the string.A
nullstring returns-1. Anullor empty array returns-1.Examples:
indexOfAny(null, *, *) returns -1 indexOfAny(*, null, *) returns -1 indexOfAny(*, [], *) returns -1 indexOfAny("zzabyycdxx", ['a','c'], 3) returns 6- Parameters:
s- the string to search (optionallynull)chars- the characters to search for (optionallynull)fromIndex- the start index within the string- Returns:
- the index within the string of the first occurrence of any
character from the array, starting the search at the specified
index within the string, or
-1if none of the characters occur
-
indexOfAny
Returns the index within the string of the first occurrence of any character from the array, up to and including the specified end index within the string, starting the search at the specified start index within the string.A
nullstring returns-1. Anullor empty array returns-1.Examples:
indexOfAny(null, *, *, *) returns -1 indexOfAny(*, null, *, *) returns -1 indexOfAny(*, [], *, *) returns -1 indexOfAny("zzabyycdxx", ['a','c'], 3, 7) returns 6- Parameters:
s- the string to search (optionallynull)chars- the characters to search for (optionallynull)fromIndex- the start index within the stringtoIndex- the end index within the string- Returns:
- the index within the string of the first occurrence of any
character from the array, up to and including the specified end
index within the string, starting the search at the specified
start index within the string, or
-1if none of the characters occur
-
indexOfAny
Returns the index within the string of the first occurrence of any string from the array.A
nullstring returns-1. Anullor empty array returns-1, but an array containing""returns0if the string is notnull.Examples:
indexOfAny(null, *) returns -1 indexOfAny(*, null) returns -1 indexOfAny(*, [null]) returns -1 indexOfAny(*, []) returns -1 indexOfAny("zzabyycdxx", ["ab","cd"]) returns 2 indexOfAny("zzabyycdxx", ["cd","ab"]) returns 2 indexOfAny("zzabyycdxx", ["mn","op"]) returns -1 indexOfAny("zzabyycdxx", ["mn",""]) returns 0- Parameters:
s- the string (optionallynull)texts- the strings to search for (optionallynull)- Returns:
- the index within the string of the first occurrence of any string
from the array,
0if the search array contains"", or-1if none of the strings occur
-
indexOfAny
Returns the index within the string of the first occurrence of any string from the array, starting the search at the specified index within the string.A
nullstring returns-1. Anullor empty array returns-1, but an array containing""returns the specified start index if the string is notnull.Examples:
indexOfAny(null, *, *) returns -1 indexOfAny(*, null, *) returns -1 indexOfAny(*, [null], *) returns -1 indexOfAny(*, [], *) returns -1 indexOfAny("zzabyycdxx", ["ab","cd"], 3) returns 6 indexOfAny("zzabyycdxx", ["cd","ab"], 3) returns 6 indexOfAny("zzabyycdxx", ["mn","op"], *) returns -1 indexOfAny("zzabyycdxx", ["mn",""], 3) returns 3- Parameters:
s- the string to search (optionallynull)texts- the strings to search for (optionallynull)fromIndex- the start index within the string- Returns:
- the index within the string of the first occurrence of any string
from the array, starting the search at the specified index within
the string, the start index if the search array contains
"", or-1if none of the strings occur
-
indexOfAny
Returns the index within the string of the first occurrence of any string from the array, up to and including the specified end index within the string, starting the search at the specified start index within the string.A
nullstring returns-1. Anullor empty array returns-1, but an array containing""returns the specified start index if the string is notnull.Examples:
indexOfAny(null, *, *, *) returns -1 indexOfAny(*, null, *, *) returns -1 indexOfAny(*, [null], *, *) returns -1 indexOfAny(*, [], *, *) returns -1 indexOfAny("zzabyycdxx", ["ab","cd"], 3, 7) returns 6 indexOfAny("zzabyycdxx", ["cd","ab"], 2, 7) returns 2 indexOfAny("zzabyycdxx", ["mn","op"], *, *) returns -1 indexOfAny("zzabyycdxx", ["mn",""], 3, *) returns 3- Parameters:
s- the string to search (optionallynull)texts- the strings to search for (optionallynull)fromIndex- the start index within the stringtoIndex- the end index within the string- Returns:
- the index within the string of the first occurrence of any string
from the array, up to and including the specified end index
within the string, starting the search at the specified start
index within the string, the start index if the search array
contains
"", or-1if none of the strings occur
-
insert
Inserts one string into the other at the specified offset index.- Parameters:
s- the original stringinsert- the string to be inserted into the original stringoffset- the index of the original string where the insertion should take place- Returns:
- a string representing the original string with the other string
inserted at the specified offset index, or
nullif the original string isnull
-
isLowerCase
Returnstrueif all the characters in stringsare lower case, ignoring any non-alphabetic characters.- Parameters:
s- the string in which to search- Returns:
trueif all the characters in stringsare lower case, ignoring any non-alphabetic characters;falseotherwise
-
isUpperCase
Returnstrueif all the characters in stringsare upper case, ignoring any non-alphabetic characters.- Parameters:
s- the string in which to search- Returns:
trueif all the characters in stringsare upper case, ignoring any non-alphabetic characters;falseotherwise
-
lastIndexOfAny
Returns the index within the string of the last occurrence of any character from the array.A
nullstring returns-1. Anullor empty array returns-1.Examples:
lastIndexOfAny(null, *) returns -1 lastIndexOfAny(*, null) returns -1 lastIndexOfAny(*, []) returns -1 lastIndexOfAny("zzabyycdxx", ['a','c']) returns 6 lastIndexOfAny("zzabyycdxx", ['c','a']) returns 6 lastIndexOfAny("zzabyycdxx", ['m','n']) returns -1- Parameters:
s- the string to search (optionallynull)chars- the characters to search for (optionallynull)- Returns:
- the index within the string of the last occurrence of any
character from the array, or
-1if none of the characters occur
-
lastIndexOfAny
Returns the index within the string of the last occurrence of any character from the array, starting the search at the specified index within the string.A
nullstring returns-1. Anullor empty array returns-1.Examples:
lastIndexOfAny(null, *, *) returns -1 lastIndexOfAny(*, null, *) returns -1 lastIndexOfAny(*, [], *) returns -1 lastIndexOfAny("zzabyycdxx", ['a','c'], 5) returns 2 lastIndexOfAny("zzabyycdxx", ['m','n'], *) returns -1- Parameters:
s- the string to search (optionallynull)chars- the characters to search for (optionallynull)toIndex- the end index within the string- Returns:
- the index within the string of the last occurrence of any
character from the array, starting the search at the specified
index within the string, or
-1if none of the characters occur
-
lastIndexOfAny
Returns the index within the string of the last occurrence of any character from the array, up to and including the specified end index within the string, starting the search at the specified start index within the string.A
nullstring returns-1. Anullor empty array returns-1.Examples:
lastIndexOfAny(null, *, *, *) returns -1 lastIndexOfAny(*, null, *, *) returns -1 lastIndexOfAny(*, [], *, *) returns -1 lastIndexOfAny("zzabyycdxx", ['a','c'], 5, 7) returns 6 lastIndexOfAny("zzabyycdxx", ['m','n'], *, *) returns -1- Parameters:
s- the string to search (optionallynull)chars- the characters to search for (optionallynull)fromIndex- the start index within the stringtoIndex- the end index within the string- Returns:
- the index within the string of the last occurrence of any
character from the array, up to and including the specified end
index within the string, starting the search at the specified
start index within the string, or
-1if none of the characters occur
-
lastIndexOfAny
Returns the index within the string of the last occurrence of any string from the array.A
nullstring returns-1. Anullor empty array returns-1, but an array containing""returns0if the string is notnull.Examples:
lastIndexOfAny(null, *) returns -1 lastIndexOfAny(*, null) returns -1 lastIndexOfAny(*, []) returns -1 lastIndexOfAny(*, [null]) returns -1 lastIndexOfAny("zzabyycdxx", ["ab","cd"]) returns 6 lastIndexOfAny("zzabyycdxx", ["cd","ab"]) returns 6 lastIndexOfAny("zzabyycdxx", ["mn","op"]) returns -1 lastIndexOfAny("zzabyycdxx", ["mn",""]) returns 10- Parameters:
s- the string to search (optionallynull)texts- the strings to search for (optionallynull)- Returns:
- the index within the string of the last occurrence of any string
from the array,
0if the search array contains"", or-1if none of the strings occur
-
lastIndexOfAny
Returns the index within the string of the last occurrence of any string from the array, starting the search at the specified index within the string.A
nullstring returns-1. Anullor empty array returns-1, but an array containing""returns the specified start index if the string is notnull.Examples:
lastIndexOfAny(null, *, *) returns -1 lastIndexOfAny(*, null, *) returns -1 lastIndexOfAny(*, [], *) returns -1 lastIndexOfAny(*, [null], *) returns -1 lastIndexOfAny("zzabyycdxx", ["ab","cd"], 5) returns 2 lastIndexOfAny("zzabyycdxx", ["cd","ab"], 5) returns 2 lastIndexOfAny("zzabyycdxx", ["mn","op"], *) returns -1 lastIndexOfAny("zzabyycdxx", ["mn",""], 5) returns 5- Parameters:
s- the string to search (optionallynull)texts- the strings to search for (optionallynull)toIndex- the end index within the string- Returns:
- the index within the string of the last occurrence of any string
from the array, starting the search at the specified index within
the string, the start index if the search array contains
"", or-1if none of the strings occur
-
lastIndexOfAny
Returns the index within the string of the last occurrence of any string from the array, up to and including the specified end index within the string, starting the search at the specified start index within the string.A
nullstring returns-1. Anullor empty array returns-1, but an array containing""returns the specified end index if the string is notnull.Examples:
lastIndexOfAny(null, *, *, *) returns -1 lastIndexOfAny(*, null, *, *) returns -1 lastIndexOfAny(*, [], *, *) returns -1 lastIndexOfAny(*, [null], *, *) returns -1 lastIndexOfAny("zzabyycdxx", ["ab","cd"], 2, 5) returns 2 lastIndexOfAny("zzabyycdxx", ["mn","op"], *, *) returns -1 lastIndexOfAny("zzabyycdxx", ["mn",""], 2, 5) returns 5- Parameters:
s- the string to search (optionallynull)texts- the strings to search for (optionallynull)fromIndex- the start index within the stringtoIndex- the end index within the string- Returns:
- the index within the string of the last occurrence of any string
from the array, up to and including the specified end index
within the string, starting the search at the specified start
index within the string, the end index if the search array
contains
"", or-1if none of the strings occur
-
lowerCase
Converts all of the characters in the string to lower case.- Parameters:
s- the string to convert- Returns:
- the string, converted to lower case, or
nullif the string isnull - See Also:
-
lowerCase
Converts all of the characters in the arbitrary number of strings to lower case.- Parameters:
array- the array or sequence of string arguments
-
lowerCaseFirstLetter
Converts the first character of the string to lower case.- Parameters:
s- the string whose first character is to be converted- Returns:
- the string, with its first character converted to lower-case
-
matches
Returnstrueif the specified pattern occurs at any position in the string.- Parameters:
s- the stringpattern- the pattern to search for in the string- Returns:
trueif the specified pattern occurs at any position in the string
-
matchesIgnoreCase
Returnstrueif the specified pattern occurs at any position in the string, ignoring case.- Parameters:
s- the stringpattern- the pattern to search for in the string- Returns:
trueif the specified pattern occurs at any position in the string
-
merge
Merges the elements of the boolean array into a string representing a comma delimited list of its values.- Parameters:
array- the boolean values to merge- Returns:
- a string representing a comma delimited list of the values of the
boolean array, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of the boolean array into a string representing a delimited list of its values.- Parameters:
array- the boolean values to mergedelimiter- the delimiter- Returns:
- a string representing a comma delimited list of the values of the
boolean array, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of the character array into a string representing a comma delimited list of its values.- Parameters:
array- the characters to merge- Returns:
- a string representing a comma delimited list of the values of the
character array, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of the character array into a string representing a delimited list of its values.- Parameters:
array- the characters to mergedelimiter- the delimiter- Returns:
- a string representing a delimited list of the values of the
character array, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of the collection by returning a string representing a comma delimited list of its values.- Parameters:
collection- the collection of objects- Returns:
- the merged collection elements, or
nullif the collection isnull
-
merge
Merges the elements of the collection by returning a string representing a delimited list of its values.- Parameters:
collection- the collection of objectsdelimiter- the string whose last index in the string marks where to begin the substring- Returns:
- the merged collection elements, or
nullif the collection isnull
-
merge
Merges the elements of an array of double-precision decimal numbers by returning a string representing a comma delimited list of its values.- Parameters:
array- the doubles to merge- Returns:
- a string representing a comma delimited list of the values of the
array of double-precision decimal numbers, an empty string if the
array is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of double-precision decimal numbers by returning a string representing a delimited list of its values.- Parameters:
array- the doubles to mergedelimiter- the delimiter- Returns:
- a string representing a delimited list of the values of the array
of double-precision decimal numbers, an empty string if the array
is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of decimal numbers into a string representing a comma delimited list of its values.- Parameters:
array- the floats to merge- Returns:
- a string representing a comma delimited list of the values of the
array of decimal numbers, an empty string if the array is empty,
or
nullif the array isnull
-
merge
Merges the elements of an array of decimal numbers into a string representing a delimited list of its values.- Parameters:
array- the floats to mergedelimiter- the delimiter- Returns:
- a string representing a delimited list of the values of the array
of decimal numbers, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of integers into a string representing a comma delimited list of its values.- Parameters:
array- the integers to merge- Returns:
- a string representing a comma delimited list of the values of the
array of integers, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of integers into a string representing a delimited list of its values.- Parameters:
array- the integers to mergedelimiter- the delimiter- Returns:
- a string representing a delimited list of the values of the array
of integers, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of long integers by returning a string representing a comma delimited list of its values.- Parameters:
array- the long integers to merge- Returns:
- a string representing a comma delimited list of the values of the
array of long integers, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of long integers by returning a string representing a delimited list of its values.- Parameters:
array- the long integers to mergedelimiter- the delimiter- Returns:
- a string representing a delimited list of the values of the array
of long integers, an empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of objects into a string representing a comma delimited list of the objects.- Parameters:
array- the objects to merge- Returns:
- a string representing a comma delimited list of the objects, an
empty string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of objects into a string representing a delimited list of the objects.- Parameters:
array- the objects to mergedelimiter- the delimiter- Returns:
- a string representing a delimited list of the objects, an empty
string if the array is empty, or
nullif the array isnull
-
merge
Merges the elements of an array of short integers by returning a string representing a comma delimited list of its values.- Parameters:
array- the short integers to merge- Returns:
- a string representing a comma delimited list of the values of the
array of short integers, an empty string if the array is empty,
or
nullif the array isnull
-
merge
Merges the elements of an array of short integers by returning a string representing a delimited list of its values.- Parameters:
array- the short integers to mergedelimiter- the delimiter- Returns:
- a string representing a delimited list of the values of the array
of short integers, an empty string if the array is empty, or
nullif the array isnull
-
quote
Returns the string enclosed by apostrophes.Example:
quote("Hello, World!") returns "'Hello, World!'"- Parameters:
s- the string to enclose in apostrophes- Returns:
- the string enclosed by apostrophes, or
nullif the string isnull
-
quote
Returns the string enclosed by the quote character.Example:
quote("PATH", '%') returns "%PATH%"- Parameters:
s- the string to enclose in quotesquote- the character to insert to insert to the beginning of and append to the end of the string- Returns:
- the string enclosed in the quote characters, or
nullif the string isnull
-
quote
Returns the string enclosed by the quote strings.Example:
quote("WARNING", "!!!") returns "!!!WARNING!!!"- Parameters:
s- the string to enclose in quotesquote- the quote string to insert to insert to the beginning of and append to the end of the string- Returns:
- the string enclosed in the quote strings, or
nullif the string isnull
-
randomId
Returns a randomized string of four lower case, alphabetic characters.- Returns:
- a randomized string of four lower case, alphabetic characters
-
randomId
Returns a randomized string with the length informed and only alphabetic characters.- Returns:
- a randomized string with the length informed and only alphabetic characters.
-
randomString
Returns a randomized string of eight characters consisting of lower case letters, upper case letters, and single-digit whole numbers.- Returns:
- a randomized string of eight characters consisting of lower case letters, upper case letters, and single-digit whole numbers
-
randomString
Returns a randomized string of the specified length consisting of lower case letters, upper case letters, and single-digit whole numbers.- Parameters:
length- the character length of the randomized string- Returns:
- a randomized string of the specified length consisting of lower case letters, upper case letters, and single-digit whole numbers
-
read
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
readLines
- Throws:
IOException
-
removeChar
-
removeChars
-
removeFirst
-
removeFromList
Removes theremovestring from stringsthat represents a list of comma delimited strings.The resulting string ends with a comma even if the original string does not.
Examples:
remove("red,blue,green,yellow", "blue") returns "red,green,yellow," remove("blue", "blue") returns "" remove("blue,", "blue") returns ""- Parameters:
s- the string representing the list of comma delimited stringselement- the string to remove- Returns:
- a string representing the list of comma delimited strings with
the
removestring removed, ornullif the original string, the string to remove, or the delimiter isnull
-
removeFromList
Removes theremovestring from stringsthat represents a list of delimited strings.The resulting string ends with the delimiter even if the original string does not.
Examples:
remove("red;blue;green;yellow", "blue", ";") returns "red;green;yellow;" remove("blue", "blue", ";") returns "" remove("blue;", "blue", ";") returns ""- Parameters:
s- the string representing the list of delimited stringselement- the string to removedelimiter- the delimiter- Returns:
- a string representing the list of delimited strings with the
removestring removed, ornullif the original string, the string to remove, or the delimiter isnull
-
removeLast
-
removeSubstring
-
removeSubstrings
-
replace
Replaces all occurrences of the character with the new character.- Parameters:
s- the original stringoldSub- the character to be searched for and replaced in the original stringnewSub- the character with which to replace theoldSubcharacter- Returns:
- a string representing the original string with all occurrences of
the
oldSubcharacter replaced with thenewSubcharacter, ornullif the original string isnull
-
replace
Replaces all occurrences of the character with the new string.- Parameters:
s- the original stringoldSub- the character to be searched for and replaced in the original stringnewSub- the string with which to replace theoldSubcharacter- Returns:
- a string representing the original string with all occurrences of
the
oldSubcharacter replaced with the stringnewSub, ornullif the original string isnull
-
replace
-
replace
-
replace
Replaces all occurrences of the string with the new string.- Parameters:
s- the original stringoldSub- the string to be searched for and replaced in the original stringnewSub- the string with which to replace theoldSubstring- Returns:
- a string representing the original string with all occurrences of
the
oldSubstring replaced with the stringnewSub, ornullif the original string isnull
-
replace
Replaces all occurrences of the string with the new string, starting from the specified index.- Parameters:
s- the original stringoldSub- the string to be searched for and replaced in the original stringnewSub- the string with which to replace theoldSubstringfromIndex- the index of the original string from which to begin searching- Returns:
- a string representing the original string with all occurrences of
the
oldSubstring occurring after the specified index replaced with the stringnewSub, ornullif the original string isnull
-
replace
Replaces all occurrences of the keywords found in the substring, defined by the beginning and ending strings, with the new values.For example, with the following initialized variables:
String s = "http://www.example-url/${userId}"; String begin = "${"; String end = "}"; Map<String, String> values = new HashMap<String, String>(); values.put("userId", "jbloggs");replace(s, begin, end, values)returns"http://www.example-url/jbloggs"- Parameters:
s- the original stringbegin- the string preceding the substring to be modified. This string is excluded from the result.end- the string following the substring to be modified. This string is excluded from the result.values- the key-value map values- Returns:
- a string representing the original string with all occurrences of
the of the keywords found in the substring, replaced with the new
values.
nullis returned if the original string, the beginning string, the ending string, or the key-map values arenull.
-
replace
-
replace
Replaces all occurrences of the elements of the string array with the corresponding elements of the new string array.- Parameters:
s- the original stringoldSubs- the strings to be searched for and replaced in the original stringnewSubs- the strings with which to replace theoldSubsstrings- Returns:
- a string representing the original string with all occurrences of
the
oldSubsstrings replaced with the correspondingnewSubsstrings, ornullif the original string, theoldSubsarray, or thenewSubsisnull
-
replace
Replaces all occurrences of the elements of the string array with the corresponding elements of the new string array, optionally replacing only substrings that are surrounded by word boundaries.Examples:
replace("redorangeyellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, false) returns "REDORANGEYELLOW" replace("redorangeyellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, true) returns "redorangeyellow" replace("redorange yellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, false) returns "REDORANGE YELLOW" replace("redorange yellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, true) returns "redorange YELLOW" replace("red orange yellow", {"red", "orange", "yellow"}, {"RED","ORANGE", "YELLOW"}, false) returns "RED ORANGE YELLOW" replace("redorange.yellow", {"red", "orange", "yellow"}, {"RED","ORANGE", * "YELLOW"}, true) returns "redorange.YELLOW"- Parameters:
s- the original stringoldSubs- the strings to be searched for and replaced in the original stringnewSubs- the strings with which to replace theoldSubsstringsexactMatch- whether or not to replace only substrings ofsthat are surrounded by word boundaries- Returns:
- if
exactMatchistrue, a string representing the original string with all occurrences of theoldSubsstrings that are surrounded by word boundaries replaced with the correspondingnewSubsstrings, or else a string representing the original string with all occurrences of theoldSubsstrings replaced with the correspondingnewSubsstrings, ornullif the original string, theoldSubsarray, or thenewSubsisnull
-
replaceFirst
Replaces the first occurrence of the character with the new character.- Parameters:
s- the original stringoldSub- the character whose first occurrence in the original string is to be searched for and replacednewSub- the character with which to replace the first occurrence of theoldSubcharacter- Returns:
- a string representing the original string except with the first
occurrence of the character
oldSubreplaced with the characternewSub
-
replaceFirst
Replaces the first occurrence of the character with the new string.- Parameters:
s- the original stringoldSub- the character whose first occurrence in the original string is to be searched for and replacednewSub- the string with which to replace the first occurrence of theoldSubcharacter- Returns:
- a string representing the original string except with the first
occurrence of the character
oldSubreplaced with the stringnewSub
-
replaceFirst
Replaces the first occurrence of the string with the new string.- Parameters:
s- the original stringoldSub- the string whose first occurrence in the original string is to be searched for and replacednewSub- the string with which to replace the first occurrence of theoldSubstring- Returns:
- a string representing the original string except with the first
occurrence of the string
oldSubreplaced with the stringnewSub
-
replaceFirst
Replaces the first occurrences of the elements of the string array with the corresponding elements of the new string array, beginning the element search from the index position.- Parameters:
s- the original stringoldSub- the strings whose first occurrences are to be searched for and replaced in the original stringnewSub- the strings with which to replace the first occurrences of theoldSubsstringsfromIndex- the start index within the string- Returns:
- a string representing the original string with the first
occurrences of the
oldSubsstrings replaced with the correspondingnewSubsstrings, ornullif the original string, theoldSubsstring, or thenewSubsstring isnull
-
replaceFirst
Replaces the first occurrences of the elements of the string array with the corresponding elements of the new string array.- Parameters:
s- the original stringoldSubs- the strings whose first occurrences are to be searched for and replaced in the original stringnewSubs- the strings with which to replace the first occurrences of theoldSubsstrings- Returns:
- a string representing the original string with the first
occurrences of the
oldSubsstrings replaced with the correspondingnewSubsstrings, ornullif the original string, theoldSubsarray, or thenewSubsisnull
-
replaceLast
Replaces the last occurrence of the character with the new character.- Parameters:
s- the original stringoldSub- the character whose last occurrence in the original string is to be searched for and replacednewSub- the character with which to replace the last occurrence of theoldSubcharacter- Returns:
- a string representing the original string except with the first
occurrence of the character
oldSubreplaced with the characternewSub
-
replaceLast
Replaces the last occurrence of the character with the new string.- Parameters:
s- the original stringoldSub- the character whose last occurrence in the original string is to be searched for and replacednewSub- the string with which to replace the last occurrence of theoldSubcharacter- Returns:
- a string representing the original string except with the last
occurrence of the character
oldSubreplaced with the stringnewSub
-
replaceLast
Replaces the last occurrence of the stringoldSubin the stringswith the stringnewSub.- Parameters:
s- the original stringoldSub- the string whose last occurrence in the original string is to be searched for and replacednewSub- the string with which to replace the last occurrence of theoldSubstring- Returns:
- a string representing the original string except with the last
occurrence of the string
oldSubreplaced with the stringnewSub
-
replaceLast
Replaces the last occurrences of the elements of the string array with the corresponding elements of the new string array.- Parameters:
s- the original stringoldSubs- the strings whose last occurrences are to be searched for and replaced in the original stringnewSubs- the strings with which to replace the last occurrences of theoldSubsstrings- Returns:
- a string representing the original string with the last
occurrences of the
oldSubsstrings replaced with the correspondingnewSubsstrings, ornullif the original string, theoldSubsarray, or thenewSubsisnull
-
replaceToStringBundler
public static com.liferay.petra.string.StringBundler replaceToStringBundler(String s, String begin, String end, Map<String, String> values) Replaces all occurrences of the keywords found in the substring, defined by the beginning and ending strings, with the new values. The result is returned as aStringBundler.For example, with the following initialized variables:
String s = "http://www.example-url/${userId}"; String begin = "${"; String end = "}"; Map<String, String> values = new HashMap<String, String>(); values.put("userId", "jbloggs");StringBundler sb = replaceToStringBundler(s, begin, end, values)sb.toString()returns"http://www.example-url/jbloggs"- Parameters:
s- the original stringbegin- the string preceding the substring to be modified. This string is excluded from the result.end- the string following the substring to be modified. This string is excluded from the result.values- the key-value map values- Returns:
- a string bundler representing the original string with all
occurrences of the keywords found in the substring, replaced with
the new values.
nullis returned if the original string, the beginning string, the ending string, or the key-map values arenull. - See Also:
-
replaceWithStringBundler
public static com.liferay.petra.string.StringBundler replaceWithStringBundler(String s, String begin, String end, Map<String, com.liferay.petra.string.StringBundler> values) Replaces all occurrences of the keywords found in the substring, defined by the beginning and ending strings, with the new values. The result is returned as aStringBundler.- Parameters:
s- the original stringbegin- the string preceding the substring to be modified. This string is removed from the result.end- the string following the substring to be modified. This string is removed from the result.values- the key-value map values, which has string keys andStringBundlervalues- Returns:
- a string bundler representing the original string with all
occurrences of the keywords found in the substring, replaced with
the new values.
nullis returned if the original string, the beginning string, the ending string, or the key-map values arenull.
-
shorten
Returns a string representing the original string appended with suffix "..." and then shortened to 20 characters.The suffix is only added if the original string exceeds 20 characters. If the original string exceeds 20 characters and it contains whitespace, the string is shortened at the first whitespace character.
Examples:
shorten("12345678901234567890xyz") returns "12345678901234567..." shorten("1 345678901234567890xyz") returns "1..." shorten(" 2345678901234567890xyz") returns "..." shorten("12345678901234567890") returns "12345678901234567890" shorten(" 2345678901234567890") returns " 2345678901234567890"- Parameters:
s- the original string- Returns:
- a string representing the original string shortened to 20 characters, with suffix "..." appended to it
-
shorten
Returns a string representing the original string appended with suffix "..." and then shortened to the specified length.The suffix is only added if the original string exceeds the specified length. If the original string exceeds the specified length and it contains whitespace, the string is shortened at the first whitespace character.
Examples:
shorten("123456789", 8) returns "12345..." shorten("1 3456789", 8) returns "1..." shorten(" 23456789", 8) returns "..." shorten("12345678", 8) returns "12345678" shorten(" 1234567", 8) returns " 1234567"- Parameters:
s- the original stringlength- the number of characters to limit from the original string- Returns:
- a string representing the original string shortened to the specified length, with suffix "..." appended to it
-
shorten
Returns a string representing the original string appended with the specified suffix and then shortened to the specified length.The suffix is only added if the original string exceeds the specified length. If the original string exceeds the specified length and it contains whitespace, the string is shortened at the first whitespace character.
Examples:
shorten("12345678901234", 13, "... etc.") returns "12345... etc." shorten("1 345678901234", 13, "... etc.") returns "1... etc." shorten(" 2345678901234", 13, "... etc.") returns "... etc." shorten("1234567890123", 13, "... etc.") returns "1234567890123" shorten(" 123456789012", 13, "... etc.") returns " 123456789012"- Parameters:
s- the original stringlength- the number of characters to limit from the original stringsuffix- the suffix to append- Returns:
- a string representing the original string shortened to the specified length, with the specified suffix appended to it
-
shorten
Returns a string representing the original string appended with the specified suffix and then shortened to 20 characters.The suffix is only added if the original string exceeds 20 characters. If the original string exceeds 20 characters and it contains whitespace, the string is shortened at the first whitespace character.
Examples:
shorten("12345678901234567890xyz", "... etc.") returns "123456789012... etc." shorten("1 345678901234567890xyz", "... etc.") returns "1... etc." shorten(" 2345678901234567890xyz", "... etc.") returns "... etc." shorten("12345678901234567890", "... etc.") returns "12345678901234567890" shorten(" 2345678901234567890", "... etc.") returns " 2345678901234567890"- Parameters:
s- the original stringsuffix- the suffix to append- Returns:
- a string representing the original string shortened to 20 characters, with the specified suffix appended to it
-
split
Splits stringsaround comma characters.Examples:
split("Alice,Bob,Charlie") returns {"Alice", "Bob", "Charlie"} split("Alice, Bob, Charlie") returns {"Alice", " Bob", " Charlie"}- Parameters:
s- the string to split- Returns:
- the array of strings resulting from splitting string
saround comma characters, or an empty string array ifsisnullorsis empty
-
split
Splits the stringsaround comma characters returning the boolean values of the substrings.- Parameters:
s- the string to splitx- the default value to use for a substring in case an exception occurs in getting the boolean value for that substring- Returns:
- the array of boolean values resulting from splitting string
saround comma characters, or an empty array ifsisnull
-
split
Splits the stringsaround the specified delimiter.Example:
splitLines("First;Second;Third", ';') returns {"First","Second","Third"}- Parameters:
s- the string to splitdelimiter- the delimiter- Returns:
- the array of strings resulting from splitting string
saround the specified delimiter character, or an empty string array ifsisnullor ifsis empty
-
split
Splits the stringsaround comma characters returning the double-precision decimal values of the substrings.- Parameters:
s- the string to splitx- the default value to use for a substring in case an exception occurs in getting the double-precision decimal value for that substring- Returns:
- the array of double-precision decimal values resulting from
splitting string
saround comma characters, or an empty array ifsisnull
-
split
Splits the stringsaround comma characters returning the decimal values of the substrings.- Parameters:
s- the string to splitx- the default value to use for a substring in case an exception occurs in getting the decimal value for that substring- Returns:
- the array of decimal values resulting from splitting string
saround comma characters, or an empty array ifsisnull
-
split
Splits the stringsaround comma characters returning the integer values of the substrings.- Parameters:
s- the string to splitx- the default value to use for a substring in case an exception occurs in getting the integer value for that substring- Returns:
- the array of integer values resulting from splitting string
saround comma characters, or an empty array ifsisnull
-
split
Splits the stringsaround comma characters returning the long integer values of the substrings.- Parameters:
s- the string to splitx- the default value to use for a substring in case an exception occurs in getting the long integer value for that substring- Returns:
- the array of long integer values resulting from splitting string
saround comma characters, or an empty array ifsisnull
-
split
Splits the stringsaround comma characters returning the short integer values of the substrings.- Parameters:
s- the string to splitx- the default value to use for a substring in case an exception occurs in getting the short integer value for that substring- Returns:
- the array of short integer values resulting from splitting string
saround comma characters, or an empty array ifsisnull
-
split
Splits the stringsaround the specified delimiter string.Example:
splitLines("oneandtwoandthreeandfour", "and") returns {"one","two","three","four"}- Parameters:
s- the string to splitdelimiter- the delimiter- Returns:
- the array of strings resulting from splitting string
saround the specified delimiter string, or an empty string array ifsisnullor equals the delimiter
-
split
Splits the stringsaround the specified delimiter returning the boolean values of the substrings.- Parameters:
s- the string to splitdelimiter- the delimiterx- the default value to use for a substring in case an exception occurs in getting the boolean value for that substring- Returns:
- the array of booleans resulting from splitting string
saround the specified delimiter string, or an empty array ifsisnull
-
split
Splits the stringsaround the specified delimiter returning the double-precision decimal values of the substrings.- Parameters:
s- the string to splitdelimiter- the delimiterx- the default value to use for a substring in case an exception occurs in getting the double-precision decimal value for that substring- Returns:
- the array of double-precision decimal values resulting from
splitting string
saround the specified delimiter string, or an empty array ifsisnull
-
split
Splits the stringsaround the specified delimiter returning the decimal values of the substrings.- Parameters:
s- the string to splitdelimiter- the delimiterx- the default value to use for a substring in case an exception occurs in getting the decimal value for that substring- Returns:
- the array of decimal values resulting from splitting string
saround the specified delimiter string, or an empty array ifsisnull
-
split
Splits the stringsaround the specified delimiter returning the integer values of the substrings.- Parameters:
s- the string to splitdelimiter- the delimiterx- the default value to use for a substring in case an exception occurs in getting the integer value for that substring- Returns:
- the array of integer values resulting from splitting string
saround the specified delimiter string, or an empty array ifsisnull
-
split
Splits the stringsaround the specified delimiter returning the long integer values of the substrings.- Parameters:
s- the string to splitdelimiter- the delimiterx- the default value to use for a substring in case an exception occurs in getting the long integer value for that substring- Returns:
- the array of long integer values resulting from splitting string
saround the specified delimiter string, or an empty array ifsisnull
-
split
Splits the stringsaround the specified delimiter returning the short integer values of the substrings.- Parameters:
s- the string to splitdelimiter- the delimiterx- the default value to use for a substring in case an exception occurs in getting the short integer value for that substring- Returns:
- the array of short integer values resulting from splitting string
saround the specified delimiter string, or an empty array ifsisnull
-
splitLines
Splits stringsaround return and newline characters.Example:
splitLines("Red\rBlue\nGreen") returns {"Red","Blue","Green"}- Parameters:
s- the string to split- Returns:
- the array of strings resulting from splitting string
saround return and newline characters, or an empty string array if stringsisnull
-
startsWith
Returnstrueif, ignoring case, the string starts with the specified character.- Parameters:
s- the stringbegin- the character against which the initial character of the string is to be compared- Returns:
trueif, ignoring case, the string starts with the specified character;falseotherwise
-
startsWith
Returnstrueif, ignoring case, the string starts with the specified start string.- Parameters:
s- the original stringstart- the string against which the beginning of stringsare to be compared- Returns:
trueif, ignoring case, the string starts with the specified start string;falseotherwise
-
startsWithWeight
Returns the number of starting characters thats1ands2have in common before their characters deviate.- Parameters:
s1- string 1s2- string 2- Returns:
- the number of starting characters that
s1ands2have in common before their characters deviate
-
stripBetween
Returns a string representing the combination of the substring ofsup to but not including the stringbeginconcatenated with the substring ofsafter but not including the stringend.Example:
stripBetween("One small step for man, one giant leap for mankind", "step", "giant ") returns "One small leap for mankind"- Parameters:
s- the string from which to strip a substringbegin- the beginning characters of the substring to be removedend- the ending characters of the substring to be removed- Returns:
- a string representing the combination of the substring of
sup to but not including the stringbeginconcatenated with the substring ofsafter but not including the stringend, or the original string if the value ofs,begin, orendarenull
-
stripCDATA
Returns a string representing the stringswith its<![CDATA[]]>wrapper removed.Example:
stripCDATA("<![CDATA[One small step for man]]>") returns "One small step for man"- Parameters:
s- the string from which to strip its CDATA wrapper- Returns:
- a string representing the string
swith its<![CDATA[]]>wrapper removed, ornullifsisnull
-
stripParentheticalSuffix
Returns a string representing the stringswithout an appended parenthetical suffix. If there is not a space directly before the opening parenthesis, the parenthetical suffix is not stripped.Examples:
stripParentheticalSuffix("file") returns "file" stripParentheticalSuffix("file (0)") returns "file" stripParentheticalSuffix("file (0 0)") returns "file" stripParentheticalSuffix("file(0)") returns "file(0)"- Parameters:
s- the string from which to strip its parenthetical suffix- Returns:
- a string representing the string
swithout an appended parenthetical suffix
-
toCharCode
Returns a string representing the Unicode character codes of the characters comprising the strings.Examples:
toCharCode("a") returns "97" toCharCode("b") returns "98" toCharCode("c") returns "99" toCharCode("What's for lunch?") returns "87104971163911532102111114321081171109910463"- Parameters:
s- the string whose character codes are to be represented- Returns:
- a string representing the Unicode character codes of the
characters comprising the string
s
-
toHexString
Returns a string representing the hexidecimal character code of the integer.Examples:
toHexString(10) returns "a" toHexString(15) returns "f" toHexString(10995) returns "2af3"- Parameters:
i- the integer to convert- Returns:
- a string representing the hexidecimal character code of the integer
-
toHexString
Returns a string representing the hexidecimal character code of the long integer.Example:
toHexString(12345678910L) returns "2dfdc1c3e"- Parameters:
l- the long integer to convert- Returns:
- a string representing the hexidecimal character code of the long integer
-
toHexString
Returns a string representing the hexidecimal character code of theIntegerorLongobject type. If the object is not an instance of these types, the object's original value is returned.- Parameters:
object- the object to convert- Returns:
- a string representing the hexidecimal character code of the object
-
toLowerCase
Converts all of the characters in the string to lower case, based on the portal instance's default locale.- Parameters:
s- the string to convert- Returns:
- the string, converted to lower case, or
nullif the string isnull
-
toLowerCase
Converts all of the characters in the string to lower case, based on the locale.- Parameters:
s- the string to convertlocale- apply this locale's rules- Returns:
- the string, converted to lower case, or
nullif the string isnull - See Also:
-
GetterUtil#_toLowerCase
-
toUpperCase
Converts all of the characters in the string to upper case, based on the portal instance's default locale.- Parameters:
s- the string to convert- Returns:
- the string, converted to upper case, or
nullif the string isnull
-
toUpperCase
Converts all of the characters in the string to upper case, based on the locale.- Parameters:
s- the string to convertlocale- apply this locale's rules- Returns:
- the string, converted to upper case, or
nullif the string isnull
-
trim
Trims all leading and trailing whitespace from the string.- Parameters:
s- the original string- Returns:
- a string representing the original string with all leading and trailing whitespace removed
-
trim
Trims leading and trailing whitespace from the string, up to but not including the whitespace character specified byc.Examples:
trim(" \tHey\t ", '\t') returns "\tHey\t" trim(" \t Hey \t ", '\t') returns "\t Hey \t"- Parameters:
s- the original stringc- the whitespace character to limit trimming- Returns:
- a string representing the original string with leading and
trailing whitespace removed, up to but not including the
whitespace character specified by
c
-
trim
Trims leading and trailing whitespace from the string, up to but not including the whitespace characters specified byexceptions.- Parameters:
s- the original stringexceptions- the whitespace characters to limit trimming- Returns:
- a string representing the original string with leading and
trailing whitespace removed, up to but not including the
whitespace characters specified by
exceptions
-
trimLeading
Trims all leading whitespace from the string.- Parameters:
s- the original string- Returns:
- a string representing the original string with all leading whitespace removed
-
trimLeading
Trims leading whitespace from the string, up to but not including the whitespace character specified byc.- Parameters:
s- the original stringc- the whitespace character to limit trimming- Returns:
- a string representing the original string with leading whitespace
removed, up to but not including the whitespace character
specified by
c
-
trimLeading
Trims leading whitespace from the string, up to but not including the whitespace characters specified byexceptions.- Parameters:
s- the original stringexceptions- the whitespace characters to limit trimming- Returns:
- a string representing the original string with leading whitespace
removed, up to but not including the whitespace characters
specified by
exceptions
-
trimTrailing
Trims all trailing whitespace from the string.- Parameters:
s- the original string- Returns:
- a string representing the original string with all trailing whitespace removed
-
trimTrailing
Trims trailing whitespace from the string, up to but not including the whitespace character specified byc.- Parameters:
s- the original stringc- the whitespace character to limit trimming- Returns:
- a string representing the original string with trailing
whitespace removed, up to but not including the whitespace
character specified by
c
-
trimTrailing
Trims trailing whitespace from the string, up to but not including the whitespace characters specified byexceptions.- Parameters:
s- the original stringexceptions- the whitespace characters to limit trimming- Returns:
- a string representing the original string with trailing
whitespace removed, up to but not including the whitespace
characters specified by
exceptions
-
unquote
Removes leading and trailing double and single quotation marks from the string.- Parameters:
s- the original string- Returns:
- a string representing the original string with leading and
trailing double and single quotation marks removed, or the
original string if the original string is a
nullor empty
-
upperCase
Converts all of the characters in the string to upper case.- Parameters:
s- the string to convert- Returns:
- the string, converted to upper-case, or
nullif the string isnull - See Also:
-
upperCaseFirstLetter
Converts the first character of the string to upper case.- Parameters:
s- the string whose first character is to be converted- Returns:
- the string, with its first character converted to upper-case
-
wildcardMatches
public static boolean wildcardMatches(String s, String wildcard, char singleWildcardCharacter, char multipleWildcardCharacter, char escapeWildcardCharacter, boolean caseSensitive) Returnstrueif the string matches the wildcard pattern.For example, with the following initialized variables:
String s = "*master"; String wildcard = "/*m?st*"; char singleWildcardCharacter = '?'; char multipleWildcardCharacter = '*'; char escapeWildcardCharacter = '/'; boolean caseSensitive = false;wildcardMatches(s, wildcard, singleWildcardCharacter, multipleWildcardCharacter, escapeWildcardCharacter, caseSensitive)returnstrue- Parameters:
s- the string to be checkedwildcard- the wildcard pattern to matchsingleWildcardCharacter- the char used to match exactly one charactermultipleWildcardCharacter- the char used to match0or more charactersescapeWildcardCharacter- the char placed in front of a wildcard character to indicate that it should be interpreted as a regular charactercaseSensitive- whether to use case sensitivity- Returns:
trueif the string matches the wildcard pattern;falseotherwise
-