Package jodd.util
Class StringUtil
- java.lang.Object
-
- jodd.util.StringUtil
-
public class StringUtil extends java.lang.ObjectString utilities.
-
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringcapitalize(java.lang.String str)Capitalizes a string, changing the first letter to upper case.static java.lang.StringcompressChars(java.lang.String s, char c)Compress multiple occurrences of given char into one appearance.static booleancontainsOnlyDigits(java.lang.CharSequence string)Returnstrueif string contains only digits.static booleancontainsOnlyDigitsAndSigns(java.lang.CharSequence string)Returnstrueif stringcontains only digitsor signs plus or minus.static booleancontainsOnlyWhitespaces(java.lang.CharSequence string)Returnstrueif string contains only white spaces.static java.lang.StringconvertCharset(java.lang.String source, java.nio.charset.Charset sourceCharset, java.nio.charset.Charset newCharset)Converts string charset.static java.lang.StringconvertTabsToSpaces(java.lang.String line, int tabWidth)Converts all tabs on a line to spaces according to the provided tab width.static intcount(java.lang.String source, char c)static intcount(java.lang.String source, char c, int start)static intcount(java.lang.String source, java.lang.String sub)Counts substring occurrences in a source string.static intcount(java.lang.String source, java.lang.String sub, int start)static intcountIgnoreCase(java.lang.String source, java.lang.String sub)Count substring occurrences in a source string, ignoring case.static java.lang.Stringcrop(java.lang.String string)Crops string by setting empty strings tonull.static voidcropAll(java.lang.String... strings)Crops all elements of string array.static java.lang.StringcutBetween(java.lang.String string, java.lang.String left, java.lang.String right)Cuts a string between two other strings.static java.lang.StringcutFromIndexOf(java.lang.String string, char c)Cuts the string from the first index of provided char to the end.static java.lang.StringcutFromIndexOf(java.lang.String string, java.lang.String substring)Cuts the string from the first index of provided substring to the end.static java.lang.StringcutPrefix(java.lang.String string, java.lang.String prefix)Cuts prefix if exists.static java.lang.StringcutSuffix(java.lang.String string, java.lang.String suffix)Cuts sufix if exists.static java.lang.StringcutSurrounding(java.lang.String string, java.lang.String fix)static java.lang.StringcutSurrounding(java.lang.String string, java.lang.String prefix, java.lang.String suffix)Removes surrounding prefix and suffixes.static java.lang.StringcutToIndexOf(java.lang.String string, char c)Cuts the string from beginning to the first index of provided char.static java.lang.StringcutToIndexOf(java.lang.String string, java.lang.String substring)Cuts the string from beginning to the first index of provided substring.static java.lang.Stringdecapitalize(java.lang.String name)Utility method to take a string and convert it to normal Java variable name capitalization.static chardetectQuoteChar(java.lang.String str)Detects quote character or return 0.static booleanendsWithChar(java.lang.String s, char c)Returns if string ends with provided character.static booleanendsWithIgnoreCase(java.lang.String src, java.lang.String subS)Tests if this string ends with the specified suffix.static intendsWithOne(java.lang.String src, java.lang.String... dest)Checks if string ends with at least one string from the provided array.static intendsWithOneIgnoreCase(java.lang.String src, java.lang.String... dest)Checks if string ends with at least one string from the provided array.static booleanequals(java.lang.String[] as, java.lang.String[] as1)Compares two string arrays.static booleanequals(java.lang.String s1, java.lang.String s2)Compares 2 strings.static booleanequalsIgnoreCase(java.lang.String[] as, java.lang.String[] as1)Compares two string arrays.static intequalsOne(java.lang.String src, java.lang.String... dest)Compares string with at least one from the provided array.static intequalsOneIgnoreCase(java.lang.String src, java.lang.String... dest)Compares string with at least one from the provided array, ignoring case.static java.lang.StringescapeJava(java.lang.String string)Escapes a string using java rules.static java.lang.StringfindCommonPrefix(java.lang.String... strings)Finds common prefix for several strings.static java.lang.StringfromCamelCase(java.lang.String input, char separator)Changes CamelCase string to lower case words separated by provided separator character.static java.lang.StringifNotNull(java.lang.String input, java.util.function.Function<java.lang.String,java.lang.String> stringFunction)Executes function on a string if notnull.static intindexOf(java.lang.String src, char c, int startIndex, int endIndex)Finds the first occurrence of a character in the given source but within limited range (start, end].static int[]indexOf(java.lang.String s, java.lang.String... arr)Finds the very first index of a substring from the specified array.static int[]indexOf(java.lang.String s, java.lang.String[] arr, int offset)Finds the very first index of a substring from the specified array.static intindexOf(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)Finds first occurrence of a substring in the given source but within limited range [start, end).static intindexOfChars(java.lang.String string, char[] chars)static intindexOfChars(java.lang.String string, char[] chars, int startindex)Returns the very first index of any char from provided string, starting from specified index offset.static intindexOfChars(java.lang.String string, java.lang.String chars)static intindexOfChars(java.lang.String string, java.lang.String chars, int startindex)Returns the very first index of any char from provided string, starting from specified index offset.static intindexOfIgnoreCase(java.lang.String src, char c, int startIndex, int endIndex)Finds the first occurrence of a character in the given source but within limited range (start, end].static intindexOfIgnoreCase(java.lang.String src, java.lang.String subS)Finds first index of a substring in the given source string with ignored case.static int[]indexOfIgnoreCase(java.lang.String s, java.lang.String... arr)Finds the very first index of a substring from the specified array.static int[]indexOfIgnoreCase(java.lang.String s, java.lang.String[] arr, int start)Finds the very first index of a substring from the specified array.static intindexOfIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)Finds first index of a substring in the given source string with ignored case.static intindexOfIgnoreCase(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)Finds first index of a substring in the given source string and range with ignored case.static intindexOfNonWhitespace(java.lang.String string)static intindexOfNonWhitespace(java.lang.String string, int startindex)static intindexOfNonWhitespace(java.lang.String string, int startindex, int endindex)static int[]indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary)static int[]indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, char escape)static int[]indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, char escape, int offset)Returns indexes of the first string region.static int[]indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, int offset)Returns indexes of the first region without escaping character.static intindexOfUnescapedChar(java.lang.String src, char sub, char escapeChar)static intindexOfUnescapedChar(java.lang.String src, char sub, char escapeChar, int startIndex)static intindexOfWhitespace(java.lang.String string)Returns first index of a whitespace character.static intindexOfWhitespace(java.lang.String string, int startindex)static intindexOfWhitespace(java.lang.String string, int startindex, int endindex)Returns first index of a whitespace character, starting from specified index offset.static java.lang.Stringinsert(java.lang.String src, java.lang.String insert)static java.lang.Stringinsert(java.lang.String src, java.lang.String insert, int offset)Inserts a string on provided offset.static booleanisAllBlank(java.lang.String... strings)Determines if string array contains just blank strings.static booleanisAllEmpty(java.lang.String... strings)Determines if string array contains empty strings.static booleanisBlank(java.lang.CharSequence string)Determines if a string is blank (nullorcontainsOnlyWhitespaces(CharSequence)).static booleanisCharAtEqual(java.lang.String string, int index, char charToCompare)Safely compares provided char with char on given location.static booleanisCharAtEscaped(java.lang.String src, int ndx, char escapeChar)Returnstrueif character at provided index position is escaped by escape character.static booleanisEmpty(java.lang.CharSequence string)Determines if a string is empty (nullor zero-length).static booleanisNotBlank(java.lang.CharSequence string)Determines if string is not blank.static booleanisNotEmpty(java.lang.CharSequence string)Determines if a string is not empty.static booleanisSubstringAt(java.lang.String string, java.lang.String substring, int offset)Returnstrueif substring exist at given offset in a string.static java.lang.Stringjoin(java.lang.Object[] array)Joins an array of objects into one string without separators.static java.lang.Stringjoin(java.lang.Object[] array, char separator)Joins an array of objects into one string with separator.static java.lang.Stringjoin(java.lang.Object[] array, java.lang.String separator)Joins an array of objects into one string with separator.static java.lang.Stringjoin(java.util.Collection collection, char separator)Joins an collection of objects into one string with separator.static java.lang.Stringjoin(java.util.Collection collection, java.lang.String separator)static intlastIndexOf(java.lang.String src, char c, int startIndex, int endIndex)Finds last index of a character in the given source string in specified range [end, start]static int[]lastIndexOf(java.lang.String s, java.lang.String... arr)Finds the very last index of a substring from the specified array.static int[]lastIndexOf(java.lang.String s, java.lang.String[] arr, int fromIndex)Finds the very last index of a substring from the specified array.static intlastIndexOf(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)Finds last index of a substring in the given source string in specified range [end, start] SeeindexOf(String, String, int, int)for details about the speed.static intlastIndexOfIgnoreCase(java.lang.String src, char c, int startIndex, int endIndex)Finds last index of a character in the given source string in specified range [end, start]static intlastIndexOfIgnoreCase(java.lang.String s, java.lang.String subS)Finds last index of a substring in the given source string with ignored case.static int[]lastIndexOfIgnoreCase(java.lang.String s, java.lang.String... arr)Finds the very last index of a substring from the specified array.static int[]lastIndexOfIgnoreCase(java.lang.String s, java.lang.String[] arr, int fromIndex)Finds the very last index of a substring from the specified array.static intlastIndexOfIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)Finds last index of a substring in the given source string with ignored case.static intlastIndexOfIgnoreCase(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)Finds last index of a substring in the given source string with ignored case in specified range.static intlastIndexOfNonWhitespace(java.lang.String src)static intlastIndexOfNonWhitespace(java.lang.String src, int startIndex)static intlastIndexOfNonWhitespace(java.lang.String src, int startIndex, int endIndex)static intlastIndexOfWhitespace(java.lang.String src)static intlastIndexOfWhitespace(java.lang.String src, int startIndex)Returns last index of a whitespace.static intlastIndexOfWhitespace(java.lang.String src, int startIndex, int endIndex)Returns last index of a whitespace.static java.lang.StringmaxCommonPrefix(java.lang.String one, java.lang.String two)Returns max common prefix of two strings.static java.lang.Stringprefix(java.lang.String string, java.lang.String prefix)Inserts prefix if doesn't exist.static java.lang.Stringremove(java.lang.String string, char ch)Removes a single character from string.static java.lang.Stringremove(java.lang.String s, java.lang.String sub)Removes all substring occurrences from the string.static java.lang.StringremoveChars(java.lang.String src, char... chars)Removes set of characters from string.static java.lang.StringremoveChars(java.lang.String src, java.lang.String chars)Removes all characters contained in provided string.static java.lang.StringremoveQuotes(java.lang.String string)Removes starting and ending single or double quotes.static java.lang.Stringrepeat(char c, int count)static java.lang.Stringrepeat(java.lang.String source, int count)Creates a new string that contains the provided string a number of times.static java.lang.Stringreplace(java.lang.String s, java.lang.String[] sub, java.lang.String[] with)Replaces many substring at once.static java.lang.Stringreplace(java.lang.String s, java.lang.String sub, java.lang.String with)Replaces all occurrences of a certain pattern in a string with a replacement string.static java.lang.StringreplaceChar(java.lang.String s, char sub, char with)Replaces all occurrences of a character in a string.static java.lang.StringreplaceChars(java.lang.String s, char[] sub, char[] with)Replaces all occurrences of a characters in a string.static java.lang.StringreplaceFirst(java.lang.String s, char sub, char with)Replaces the very first occurrence of a character in a string.static java.lang.StringreplaceFirst(java.lang.String s, java.lang.String sub, java.lang.String with)Replaces the very first occurrence of a substring with supplied string.static java.lang.StringreplaceIgnoreCase(java.lang.String s, java.lang.String[] sub, java.lang.String[] with)Replaces many substring at once.static java.lang.StringreplaceLast(java.lang.String s, char sub, char with)Replaces the very last occurrence of a character in a string.static java.lang.StringreplaceLast(java.lang.String s, java.lang.String sub, java.lang.String with)Replaces the very last occurrence of a substring with supplied string.static java.lang.Stringreverse(java.lang.String s)Reverse a string.static java.lang.Stringshorten(java.lang.String s, int length, java.lang.String suffix)Shorten string to given length.static java.lang.String[]split(java.lang.String src, java.lang.String delimiter)Splits a string in several parts (tokens) that are separated by delimiter.static java.lang.String[]splitc(java.lang.String src, char delimiter)Splits a string in several parts (tokens) that are separated by single delimiter characters.static java.lang.String[]splitc(java.lang.String src, char[] delimiters)Splits a string in several parts (tokens) that are separated by delimiter characters.static java.lang.String[]splitc(java.lang.String src, java.lang.String d)Splits a string in several parts (tokens) that are separated by delimiter characters.static booleanstartsWithChar(java.lang.String s, char c)Returns if string starts with given character.static booleanstartsWithIgnoreCase(java.lang.String src, java.lang.String subS)Tests if this string starts with the specified prefix with ignored case.static booleanstartsWithIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)Tests if this string starts with the specified prefix with ignored case and with the specified prefix beginning a specified index.static intstartsWithOne(java.lang.String src, java.lang.String... dest)Checks if string starts with at least one string from the provided array.static intstartsWithOneIgnoreCase(java.lang.String src, java.lang.String... dest)Checks if string starts with at least one string from the provided array.static java.lang.StringstripChar(java.lang.String string, char c)Strips leading and trailing char from given string.static java.lang.StringstripFromChar(java.lang.String string, char c)Strips everything from the first appearance of given char.static java.lang.StringstripLeadingChar(java.lang.String string, char c)Strips leading char if string starts with one.static java.lang.StringstripToChar(java.lang.String string, char c)Strips everything up to the first appearance of given char.static java.lang.StringstripTrailingChar(java.lang.String string, char c)Strips trailing char if string ends with one.static java.lang.Stringsubstring(java.lang.String string, int fromIndex, int toIndex)Returns a new string that is a substring of this string.static java.lang.Stringsuffix(java.lang.String string, java.lang.String suffix)Appends suffix if doesn't exist.static java.lang.Stringsurround(java.lang.String string, java.lang.String fix)static java.lang.Stringsurround(java.lang.String string, java.lang.String prefix, java.lang.String suffix)Surrounds the string with provided prefix and suffix if such missing from string.static java.lang.Stringtitle(java.lang.String string)Makes a title-cased string from given input.static java.lang.StringtoCamelCase(java.lang.String input, boolean firstCharUppercase, char separator)Converts separated string value to CamelCase.static java.lang.StringtoHexString(byte[] bytes)Converts bytes to hex string.static java.lang.StringtoLowerCase(java.lang.String s)Converts all of the characters in the string to lower case, based on the portal instance's default locale.static java.lang.StringtoLowerCase(java.lang.String s, java.util.Locale locale)Converts all of the characters in the string to lower case, based on the locale.static java.lang.StringtoSafeString(java.lang.Object value)Converts safely an object to a string.static java.lang.StringtoString(java.lang.Object value)Converts safely an object to a string.static java.lang.String[]toStringArray(java.lang.Object value)Converts an array object to array of strings, where every element of input array is converted to a string.static java.lang.StringtoUpperCase(java.lang.String s)Converts all of the characters in the string to upper case, based on the portal instance's default locale.static java.lang.StringtoUpperCase(java.lang.String s, java.util.Locale locale)Converts all of the characters in the string to upper case, based on the locale.static voidtrimAll(java.lang.String... strings)Trims array of strings.static java.lang.StringtrimDown(java.lang.String string)Trims string and sets tonullif trimmed string is empty.static voidtrimDownAll(java.lang.String... strings)Trims array of strings where empty strings are set tonull.static java.lang.StringtrimLeft(java.lang.String src)Trim whitespaces from the left.static java.lang.StringtrimRight(java.lang.String src)Trim whitespaces from the right.static java.lang.Stringtruncate(java.lang.String string, int length)Sets the maximum length of the string.static java.lang.Stringuncapitalize(java.lang.String str)Uncapitalizes aString, changing the first letter to lower case.static java.lang.StringunescapeJava(java.lang.String str)Unescapes a string using java rules.
-
-
-
Method Detail
-
replace
public static java.lang.String replace(java.lang.String s, java.lang.String sub, java.lang.String with)Replaces all occurrences of a certain pattern in a string with a replacement string. This is the fastest replace function known to author.- Parameters:
s- string to be inspectedsub- string pattern to be replacedwith- string that should go where the pattern was
-
replaceChar
public static java.lang.String replaceChar(java.lang.String s, char sub, char with)Replaces all occurrences of a character in a string.- Parameters:
s- input stringsub- character to replacewith- character to replace with
-
replaceChars
public static java.lang.String replaceChars(java.lang.String s, char[] sub, char[] with)Replaces all occurrences of a characters in a string.- Parameters:
s- input stringsub- characters to replacewith- characters to replace with
-
replaceFirst
public static java.lang.String replaceFirst(java.lang.String s, java.lang.String sub, java.lang.String with)Replaces the very first occurrence of a substring with supplied string.- Parameters:
s- source stringsub- substring to replacewith- substring to replace with
-
replaceFirst
public static java.lang.String replaceFirst(java.lang.String s, char sub, char with)Replaces the very first occurrence of a character in a string.- Parameters:
s- stringsub- char to replacewith- char to replace with
-
replaceLast
public static java.lang.String replaceLast(java.lang.String s, java.lang.String sub, java.lang.String with)Replaces the very last occurrence of a substring with supplied string.- Parameters:
s- source stringsub- substring to replacewith- substring to replace with
-
replaceLast
public static java.lang.String replaceLast(java.lang.String s, char sub, char with)Replaces the very last occurrence of a character in a string.- Parameters:
s- stringsub- char to replacewith- char to replace with
-
remove
public static java.lang.String remove(java.lang.String s, java.lang.String sub)Removes all substring occurrences from the string.- Parameters:
s- source stringsub- substring to remove
-
removeChars
public static java.lang.String removeChars(java.lang.String src, java.lang.String chars)Removes all characters contained in provided string.- Parameters:
src- source stringchars- string containing characters to remove
-
removeChars
public static java.lang.String removeChars(java.lang.String src, char... chars)Removes set of characters from string.- Parameters:
src- stringchars- characters to remove
-
remove
public static java.lang.String remove(java.lang.String string, char ch)Removes a single character from string.- Parameters:
string- source stringch- character to remove
-
equals
public static boolean equals(java.lang.String s1, java.lang.String s2)Compares 2 strings. If one of the strings isnull,falseis returned. if both string arenull,trueis returned.- Parameters:
s1- first string to compares2- second string- Returns:
trueif strings are equal, otherwisefalse
-
isEmpty
public static boolean isEmpty(java.lang.CharSequence string)
Determines if a string is empty (nullor zero-length).
-
isAllEmpty
public static boolean isAllEmpty(java.lang.String... strings)
Determines if string array contains empty strings.- See Also:
isEmpty(CharSequence)
-
isBlank
public static boolean isBlank(java.lang.CharSequence string)
Determines if a string is blank (nullorcontainsOnlyWhitespaces(CharSequence)).
-
isNotBlank
public static boolean isNotBlank(java.lang.CharSequence string)
Determines if string is not blank.
-
isAllBlank
public static boolean isAllBlank(java.lang.String... strings)
Determines if string array contains just blank strings.
-
containsOnlyWhitespaces
public static boolean containsOnlyWhitespaces(java.lang.CharSequence string)
Returnstrueif string contains only white spaces.
-
containsOnlyDigits
public static boolean containsOnlyDigits(java.lang.CharSequence string)
Returnstrueif string contains only digits.
-
containsOnlyDigitsAndSigns
public static boolean containsOnlyDigitsAndSigns(java.lang.CharSequence string)
Returnstrueif stringcontains only digitsor signs plus or minus.
-
isNotEmpty
public static boolean isNotEmpty(java.lang.CharSequence string)
Determines if a string is not empty.
-
toString
public static java.lang.String toString(java.lang.Object value)
Converts safely an object to a string.
-
toSafeString
public static java.lang.String toSafeString(java.lang.Object value)
Converts safely an object to a string. If object isnullan empty string is returned.
-
toStringArray
public static java.lang.String[] toStringArray(java.lang.Object value)
Converts an array object to array of strings, where every element of input array is converted to a string. If input is not an array, the result will still be an array with one element.
-
capitalize
public static java.lang.String capitalize(java.lang.String str)
Capitalizes a string, changing the first letter to upper case. No other letters are changed.- Parameters:
str- string to capitalize, may be null- See Also:
uncapitalize(String)
-
uncapitalize
public static java.lang.String uncapitalize(java.lang.String str)
Uncapitalizes aString, changing the first letter to lower case. No other letters are changed.- Parameters:
str- the String to uncapitalize, may be null- Returns:
- the uncapitalized String,
nullif null - See Also:
capitalize(String)
-
decapitalize
public static java.lang.String decapitalize(java.lang.String name)
Utility method to take a string and convert it to normal Java variable name capitalization. This normally means converting the first character from upper case to lower case, but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone.Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL".
- Parameters:
name- The string to be decapitalized.- Returns:
- The decapitalized version of the string.
-
title
public static java.lang.String title(java.lang.String string)
Makes a title-cased string from given input.
-
truncate
public static java.lang.String truncate(java.lang.String string, int length)Sets the maximum length of the string. Longer strings will be simply truncated.
-
substring
public static java.lang.String substring(java.lang.String string, int fromIndex, int toIndex)Returns a new string that is a substring of this string. The substring begins at the specifiedfromIndexand extends to the character at indextoIndex - 1. However, index values can be negative, and then the real index will be calculated from the strings end. This allows to specify, e.g.substring(1,-1)to cut one character from both ends of the string. IffromIndexis negative andtoIndexis 0, it will return last characters of the string. Also, this method will never throw an exception if index is out of range.
-
isSubstringAt
public static boolean isSubstringAt(java.lang.String string, java.lang.String substring, int offset)Returnstrueif substring exist at given offset in a string.
-
split
public static java.lang.String[] split(java.lang.String src, java.lang.String delimiter)Splits a string in several parts (tokens) that are separated by delimiter. Delimiter is always surrounded by two strings! If there is no content between two delimiters, empty string will be returned for that token. Therefore, the length of the returned array will always be: #delimiters + 1.Method is much, much faster then regexp
String.split(), and a bit faster thenStringTokenizer.- Parameters:
src- string to splitdelimiter- split delimiter- Returns:
- array of split strings
-
splitc
public static java.lang.String[] splitc(java.lang.String src, java.lang.String d)Splits a string in several parts (tokens) that are separated by delimiter characters. Delimiter may contains any number of character and it is always surrounded by two strings.- Parameters:
src- source to examined- string with delimiter characters- Returns:
- array of tokens
-
splitc
public static java.lang.String[] splitc(java.lang.String src, char[] delimiters)Splits a string in several parts (tokens) that are separated by delimiter characters. Delimiter may contains any number of character and it is always surrounded by two strings.- Parameters:
src- source to examinedelimiters- char array with delimiter characters- Returns:
- array of tokens
-
splitc
public static java.lang.String[] splitc(java.lang.String src, char delimiter)Splits a string in several parts (tokens) that are separated by single delimiter characters. Delimiter is always surrounded by two strings.- Parameters:
src- source to examinedelimiter- delimiter character- Returns:
- array of tokens
-
compressChars
public static java.lang.String compressChars(java.lang.String s, char c)Compress multiple occurrences of given char into one appearance.
-
indexOf
public static int indexOf(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)Finds first occurrence of a substring in the given source but within limited range [start, end). It is fastest possible code, but still originalString.indexOf(String, int)is much faster (since it uses char[] value directly) and should be used when no range is needed.- Parameters:
src- source string for examinationsub- substring to findstartIndex- starting indexendIndex- ending index- Returns:
- index of founded substring or -1 if substring not found
-
indexOf
public static int indexOf(java.lang.String src, char c, int startIndex, int endIndex)Finds the first occurrence of a character in the given source but within limited range (start, end].
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(java.lang.String src, char c, int startIndex, int endIndex)Finds the first occurrence of a character in the given source but within limited range (start, end].
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(java.lang.String src, java.lang.String subS)Finds first index of a substring in the given source string with ignored case.- Parameters:
src- source string for examinationsubS- substring to find- Returns:
- index of founded substring or -1 if substring is not found
- See Also:
indexOfIgnoreCase(String, String, int)
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)Finds first index of a substring in the given source string with ignored case. This seems to be the fastest way doing this, with common string length and content (of course, with no use of Boyer-Mayer type of algorithms). Other implementations are slower: getting char array first, lower casing the source string, using String.regionMatch etc.- Parameters:
src- source string for examinationsubS- substring to findstartIndex- starting index from where search begins- Returns:
- index of founded substring or -1 if substring is not found
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)Finds first index of a substring in the given source string and range with ignored case.- Parameters:
src- source string for examinationsub- substring to findstartIndex- starting index from where search beginsendIndex- endint index- Returns:
- index of founded substring or -1 if substring is not found
- See Also:
indexOfIgnoreCase(String, String, int)
-
lastIndexOfIgnoreCase
public static int lastIndexOfIgnoreCase(java.lang.String s, java.lang.String subS)Finds last index of a substring in the given source string with ignored case.- Parameters:
s- source stringsubS- substring to find- Returns:
- last index of founded substring or -1 if substring is not found
- See Also:
indexOfIgnoreCase(String, String, int),lastIndexOfIgnoreCase(String, String, int)
-
lastIndexOfIgnoreCase
public static int lastIndexOfIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)Finds last index of a substring in the given source string with ignored case.- Parameters:
src- source string for examinationsubS- substring to findstartIndex- starting index from where search begins- Returns:
- last index of founded substring or -1 if substring is not found
- See Also:
indexOfIgnoreCase(String, String, int)
-
lastIndexOfIgnoreCase
public static int lastIndexOfIgnoreCase(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)Finds last index of a substring in the given source string with ignored case in specified range.- Parameters:
src- source to examinesub- substring to findstartIndex- starting indexendIndex- end index- Returns:
- last index of founded substring or -1 if substring is not found
-
lastIndexOf
public static int lastIndexOf(java.lang.String src, java.lang.String sub, int startIndex, int endIndex)Finds last index of a substring in the given source string in specified range [end, start] SeeindexOf(String, String, int, int)for details about the speed.- Parameters:
src- source to examinesub- substring to findstartIndex- starting indexendIndex- end index- Returns:
- last index of founded substring or -1 if substring is not found
-
lastIndexOf
public static int lastIndexOf(java.lang.String src, char c, int startIndex, int endIndex)Finds last index of a character in the given source string in specified range [end, start]
-
lastIndexOfIgnoreCase
public static int lastIndexOfIgnoreCase(java.lang.String src, char c, int startIndex, int endIndex)Finds last index of a character in the given source string in specified range [end, start]
-
lastIndexOfWhitespace
public static int lastIndexOfWhitespace(java.lang.String src)
-
lastIndexOfWhitespace
public static int lastIndexOfWhitespace(java.lang.String src, int startIndex)Returns last index of a whitespace.
-
lastIndexOfWhitespace
public static int lastIndexOfWhitespace(java.lang.String src, int startIndex, int endIndex)Returns last index of a whitespace.
-
lastIndexOfNonWhitespace
public static int lastIndexOfNonWhitespace(java.lang.String src)
-
lastIndexOfNonWhitespace
public static int lastIndexOfNonWhitespace(java.lang.String src, int startIndex)
-
lastIndexOfNonWhitespace
public static int lastIndexOfNonWhitespace(java.lang.String src, int startIndex, int endIndex)
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(java.lang.String src, java.lang.String subS)Tests if this string starts with the specified prefix with ignored case.- Parameters:
src- source string to testsubS- starting substring- Returns:
trueif the character sequence represented by the argument is a prefix of the character sequence represented by this string;falseotherwise.
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)Tests if this string starts with the specified prefix with ignored case and with the specified prefix beginning a specified index.- Parameters:
src- source string to testsubS- starting substringstartIndex- index from where to test- Returns:
trueif the character sequence represented by the argument is a prefix of the character sequence represented by this string;falseotherwise.
-
endsWithIgnoreCase
public static boolean endsWithIgnoreCase(java.lang.String src, java.lang.String subS)Tests if this string ends with the specified suffix.- Parameters:
src- String to testsubS- suffix- Returns:
trueif the character sequence represented by the argument is a suffix of the character sequence represented by this object;falseotherwise.
-
startsWithChar
public static boolean startsWithChar(java.lang.String s, char c)Returns if string starts with given character.
-
endsWithChar
public static boolean endsWithChar(java.lang.String s, char c)Returns if string ends with provided character.
-
count
public static int count(java.lang.String source, java.lang.String sub)Counts substring occurrences in a source string.- Parameters:
source- source stringsub- substring to count- Returns:
- number of substring occurrences
-
count
public static int count(java.lang.String source, java.lang.String sub, int start)
-
count
public static int count(java.lang.String source, char c)
-
count
public static int count(java.lang.String source, char c, int start)
-
countIgnoreCase
public static int countIgnoreCase(java.lang.String source, java.lang.String sub)Count substring occurrences in a source string, ignoring case.- Parameters:
source- source stringsub- substring to count- Returns:
- number of substring occurrences
-
indexOf
public static int[] indexOf(java.lang.String s, java.lang.String... arr)Finds the very first index of a substring from the specified array. It returns an int[2] where int[0] represents the substring index and int[1] represents position where substring was found. Returnsnullif noting found.- Parameters:
s- source stringarr- string array
-
indexOf
public static int[] indexOf(java.lang.String s, java.lang.String[] arr, int offset)Finds the very first index of a substring from the specified array. It returns an int[2] where int[0] represents the substring index and int[1] represents position where substring was found. Returnsnullif noting found.- Parameters:
s- source stringarr- string arrayoffset- starting position
-
indexOfIgnoreCase
public static int[] indexOfIgnoreCase(java.lang.String s, java.lang.String... arr)Finds the very first index of a substring from the specified array. It returns an int[2] where int[0] represents the substring index and int[1] represents position where substring was found. Returnsnullif noting found.- Parameters:
s- source stringarr- string array
-
indexOfIgnoreCase
public static int[] indexOfIgnoreCase(java.lang.String s, java.lang.String[] arr, int start)Finds the very first index of a substring from the specified array. It returns an int[2] where int[0] represents the substring index and int[1] represents position where substring was found. Returnsnullif noting found.- Parameters:
s- source stringarr- string arraystart- starting position
-
lastIndexOf
public static int[] lastIndexOf(java.lang.String s, java.lang.String... arr)Finds the very last index of a substring from the specified array. It returns an int[2] where int[0] represents the substring index and int[1] represents position where substring was found. Returnsnullif noting found.- Parameters:
s- source stringarr- string array
-
lastIndexOf
public static int[] lastIndexOf(java.lang.String s, java.lang.String[] arr, int fromIndex)Finds the very last index of a substring from the specified array. It returns an int[2] where int[0] represents the substring index and int[1] represents position where substring was found. Returnsnullif noting found.- Parameters:
s- source stringarr- string arrayfromIndex- starting position
-
lastIndexOfIgnoreCase
public static int[] lastIndexOfIgnoreCase(java.lang.String s, java.lang.String... arr)Finds the very last index of a substring from the specified array. It returns an int[2] where int[0] represents the substring index and int[1] represents position where substring was found. Returnsnullif noting found.- Parameters:
s- source stringarr- string array- Returns:
- int[2]
-
lastIndexOfIgnoreCase
public static int[] lastIndexOfIgnoreCase(java.lang.String s, java.lang.String[] arr, int fromIndex)Finds the very last index of a substring from the specified array. It returns an int[2] where int[0] represents the substring index and int[1] represents position where substring was found. Returnsnullif noting found.- Parameters:
s- source stringarr- string arrayfromIndex- starting position
-
equals
public static boolean equals(java.lang.String[] as, java.lang.String[] as1)Compares two string arrays.- Parameters:
as- first string arrayas1- second string array- Returns:
trueif all array elements matches
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(java.lang.String[] as, java.lang.String[] as1)Compares two string arrays.- Parameters:
as- first string arrayas1- second string array- Returns:
- true if all array elements matches
-
replace
public static java.lang.String replace(java.lang.String s, java.lang.String[] sub, java.lang.String[] with)Replaces many substring at once. Order of string array is important.- Parameters:
s- source stringsub- substrings arraywith- replace with array- Returns:
- string with all occurrences of substrings replaced
-
replaceIgnoreCase
public static java.lang.String replaceIgnoreCase(java.lang.String s, java.lang.String[] sub, java.lang.String[] with)Replaces many substring at once. Order of string array is important.- Parameters:
s- source stringsub- substrings arraywith- replace with array- Returns:
- string with all occurrences of substrings replaced
-
equalsOne
public static int equalsOne(java.lang.String src, java.lang.String... dest)Compares string with at least one from the provided array. If at least one equal string is found, returns its index. Otherwise,-1is returned.
-
equalsOneIgnoreCase
public static int equalsOneIgnoreCase(java.lang.String src, java.lang.String... dest)Compares string with at least one from the provided array, ignoring case. If at least one equal string is found, it returns its index. Otherwise,-1is returned.
-
startsWithOne
public static int startsWithOne(java.lang.String src, java.lang.String... dest)Checks if string starts with at least one string from the provided array. If at least one string is matched, it returns its index. Otherwise,-1is returned.
-
startsWithOneIgnoreCase
public static int startsWithOneIgnoreCase(java.lang.String src, java.lang.String... dest)Checks if string starts with at least one string from the provided array. If at least one string is matched, it returns its index. Otherwise,-1is returned.
-
endsWithOne
public static int endsWithOne(java.lang.String src, java.lang.String... dest)Checks if string ends with at least one string from the provided array. If at least one string is matched, it returns its index. Otherwise,-1is returned.
-
endsWithOneIgnoreCase
public static int endsWithOneIgnoreCase(java.lang.String src, java.lang.String... dest)Checks if string ends with at least one string from the provided array. If at least one string is matched, it returns its index. Otherwise,-1is returned.
-
indexOfChars
public static int indexOfChars(java.lang.String string, java.lang.String chars)- See Also:
indexOfChars(String, String, int)
-
indexOfChars
public static int indexOfChars(java.lang.String string, java.lang.String chars, int startindex)Returns the very first index of any char from provided string, starting from specified index offset. Returns index of founded char, or-1if nothing found.
-
indexOfChars
public static int indexOfChars(java.lang.String string, char[] chars)
-
indexOfChars
public static int indexOfChars(java.lang.String string, char[] chars, int startindex)Returns the very first index of any char from provided string, starting from specified index offset. Returns index of founded char, or-1if nothing found.
-
indexOfWhitespace
public static int indexOfWhitespace(java.lang.String string)
Returns first index of a whitespace character.
-
indexOfWhitespace
public static int indexOfWhitespace(java.lang.String string, int startindex)
-
indexOfWhitespace
public static int indexOfWhitespace(java.lang.String string, int startindex, int endindex)Returns first index of a whitespace character, starting from specified index offset.
-
indexOfNonWhitespace
public static int indexOfNonWhitespace(java.lang.String string)
-
indexOfNonWhitespace
public static int indexOfNonWhitespace(java.lang.String string, int startindex)
-
indexOfNonWhitespace
public static int indexOfNonWhitespace(java.lang.String string, int startindex, int endindex)
-
stripLeadingChar
public static java.lang.String stripLeadingChar(java.lang.String string, char c)Strips leading char if string starts with one.
-
stripTrailingChar
public static java.lang.String stripTrailingChar(java.lang.String string, char c)Strips trailing char if string ends with one.
-
stripChar
public static java.lang.String stripChar(java.lang.String string, char c)Strips leading and trailing char from given string.
-
stripToChar
public static java.lang.String stripToChar(java.lang.String string, char c)Strips everything up to the first appearance of given char. Character IS included in the returned string.
-
stripFromChar
public static java.lang.String stripFromChar(java.lang.String string, char c)Strips everything from the first appearance of given char. Character IS NOT included in the returned string.
-
trimAll
public static void trimAll(java.lang.String... strings)
Trims array of strings.nullarray elements are ignored.
-
trimDownAll
public static void trimDownAll(java.lang.String... strings)
Trims array of strings where empty strings are set tonull.nullelements of the array are ignored.- See Also:
trimDown(String)
-
trimDown
public static java.lang.String trimDown(java.lang.String string)
Trims string and sets tonullif trimmed string is empty.
-
crop
public static java.lang.String crop(java.lang.String string)
Crops string by setting empty strings tonull.
-
cropAll
public static void cropAll(java.lang.String... strings)
Crops all elements of string array.
-
trimLeft
public static java.lang.String trimLeft(java.lang.String src)
Trim whitespaces from the left.
-
trimRight
public static java.lang.String trimRight(java.lang.String src)
Trim whitespaces from the right.
-
indexOfRegion
public static int[] indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary)
-
indexOfRegion
public static int[] indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, int offset)Returns indexes of the first region without escaping character.
-
indexOfRegion
public static int[] indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, char escape)
-
indexOfRegion
public static int[] indexOfRegion(java.lang.String string, java.lang.String leftBoundary, java.lang.String rightBoundary, char escape, int offset)Returns indexes of the first string region. Region is defined by its left and right boundary. Return value is an array of the following indexes:- start of left boundary index
- region start index, i.e. end of left boundary
- region end index, i.e. start of right boundary
- end of right boundary index
Escape character may be used to prefix boundaries so they can be ignored. Double escaped region will be found, and first index of the result will be decreased to include one escape character. If region is not founded,
nullis returned.
-
join
public static java.lang.String join(java.lang.Object[] array)
Joins an array of objects into one string without separators.
-
join
public static java.lang.String join(java.lang.Object[] array, char separator)Joins an array of objects into one string with separator.
-
join
public static java.lang.String join(java.util.Collection collection, char separator)Joins an collection of objects into one string with separator.
-
join
public static java.lang.String join(java.util.Collection collection, java.lang.String separator)
-
join
public static java.lang.String join(java.lang.Object[] array, java.lang.String separator)Joins an array of objects into one string with separator.
-
convertCharset
public static java.lang.String convertCharset(java.lang.String source, java.nio.charset.Charset sourceCharset, java.nio.charset.Charset newCharset)Converts string charset. If charsets are the same, the same string is returned.
-
isCharAtEqual
public static boolean isCharAtEqual(java.lang.String string, int index, char charToCompare)Safely compares provided char with char on given location.
-
surround
public static java.lang.String surround(java.lang.String string, java.lang.String fix)- See Also:
surround(String, String, String)
-
surround
public static java.lang.String surround(java.lang.String string, java.lang.String prefix, java.lang.String suffix)Surrounds the string with provided prefix and suffix if such missing from string.
-
prefix
public static java.lang.String prefix(java.lang.String string, java.lang.String prefix)Inserts prefix if doesn't exist.
-
suffix
public static java.lang.String suffix(java.lang.String string, java.lang.String suffix)Appends suffix if doesn't exist.
-
cutToIndexOf
public static java.lang.String cutToIndexOf(java.lang.String string, java.lang.String substring)Cuts the string from beginning to the first index of provided substring.
-
cutToIndexOf
public static java.lang.String cutToIndexOf(java.lang.String string, char c)Cuts the string from beginning to the first index of provided char.
-
cutFromIndexOf
public static java.lang.String cutFromIndexOf(java.lang.String string, java.lang.String substring)Cuts the string from the first index of provided substring to the end.
-
cutFromIndexOf
public static java.lang.String cutFromIndexOf(java.lang.String string, char c)Cuts the string from the first index of provided char to the end.
-
cutPrefix
public static java.lang.String cutPrefix(java.lang.String string, java.lang.String prefix)Cuts prefix if exists.
-
cutSuffix
public static java.lang.String cutSuffix(java.lang.String string, java.lang.String suffix)Cuts sufix if exists.
-
cutSurrounding
public static java.lang.String cutSurrounding(java.lang.String string, java.lang.String fix)- See Also:
cutSurrounding(String, String, String)
-
cutSurrounding
public static java.lang.String cutSurrounding(java.lang.String string, java.lang.String prefix, java.lang.String suffix)Removes surrounding prefix and suffixes.
-
cutBetween
public static java.lang.String cutBetween(java.lang.String string, java.lang.String left, java.lang.String right)Cuts a string between two other strings. If either of left and right is missing, nothing will be cut andnullis returned. If indexes of left or right strings are wrong, empty string is returned.
-
isCharAtEscaped
public static boolean isCharAtEscaped(java.lang.String src, int ndx, char escapeChar)Returnstrueif character at provided index position is escaped by escape character.
-
indexOfUnescapedChar
public static int indexOfUnescapedChar(java.lang.String src, char sub, char escapeChar)
-
indexOfUnescapedChar
public static int indexOfUnescapedChar(java.lang.String src, char sub, char escapeChar, int startIndex)
-
insert
public static java.lang.String insert(java.lang.String src, java.lang.String insert)
-
insert
public static java.lang.String insert(java.lang.String src, java.lang.String insert, int offset)Inserts a string on provided offset.
-
repeat
public static java.lang.String repeat(java.lang.String source, int count)Creates a new string that contains the provided string a number of times.
-
repeat
public static java.lang.String repeat(char c, int count)
-
reverse
public static java.lang.String reverse(java.lang.String s)
Reverse a string.
-
maxCommonPrefix
public static java.lang.String maxCommonPrefix(java.lang.String one, java.lang.String two)Returns max common prefix of two strings.
-
findCommonPrefix
public static java.lang.String findCommonPrefix(java.lang.String... strings)
Finds common prefix for several strings. Returns an empty string if arguments do not have a common prefix.
-
shorten
public static java.lang.String shorten(java.lang.String s, int length, java.lang.String suffix)Shorten string to given length.
-
toLowerCase
public static java.lang.String toLowerCase(java.lang.String s)
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
public static java.lang.String toLowerCase(java.lang.String s, java.util.Locale locale)Converts all of the characters in the string to lower case, based on the locale. More efficient thanString.toLowerCase.- Parameters:
s- the string to convertlocale- apply this locale's rules, ifnulldefault locale is used- Returns:
- the string, converted to lower case, or
nullif the string isnull
-
toUpperCase
public static java.lang.String toUpperCase(java.lang.String s)
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
public static java.lang.String toUpperCase(java.lang.String s, java.util.Locale locale)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
-
removeQuotes
public static java.lang.String removeQuotes(java.lang.String string)
Removes starting and ending single or double quotes.
-
toHexString
public static java.lang.String toHexString(byte[] bytes)
Converts bytes to hex string.
-
ifNotNull
public static java.lang.String ifNotNull(java.lang.String input, java.util.function.Function<java.lang.String,java.lang.String> stringFunction)Executes function on a string if notnull. Otherwise returns an empty string.
-
detectQuoteChar
public static char detectQuoteChar(java.lang.String str)
Detects quote character or return 0.
-
fromCamelCase
public static java.lang.String fromCamelCase(java.lang.String input, char separator)Changes CamelCase string to lower case words separated by provided separator character. The following translations are applied:- Every upper case letter in the CamelCase name is translated into
two characters, a separator and the lower case equivalent of the target character,
with three exceptions.
- For contiguous sequences of upper case letters, characters after the first
character are replaced only by their lower case equivalent, and are not
preceded by a separator (
theFOOtothe_foo). - An upper case character in the first position of the CamelCase name
is not preceded by a separator character, and is translated only to its
lower case equivalent. (
Footofooand not_foo) - An upper case character in the CamelCase name that is already preceded
by a separator character is translated only to its lower case equivalent,
and is not preceded by an additional separator. (
user_Nametouser_nameand notuser__name.
- For contiguous sequences of upper case letters, characters after the first
character are replaced only by their lower case equivalent, and are not
preceded by a separator (
- If the CamelCase name starts with a separator, then that separator is not included in the translated name, unless the CamelCase name is just one character in length, i.e., it is the separator character. This applies only to the first character of the CamelCase name.
- Every upper case letter in the CamelCase name is translated into
two characters, a separator and the lower case equivalent of the target character,
with three exceptions.
-
toCamelCase
public static java.lang.String toCamelCase(java.lang.String input, boolean firstCharUppercase, char separator)Converts separated string value to CamelCase.
-
convertTabsToSpaces
public static java.lang.String convertTabsToSpaces(java.lang.String line, int tabWidth)Converts all tabs on a line to spaces according to the provided tab width. This is not a simple tab to spaces replacement, since the resulting indentation remains the same.
-
escapeJava
public static java.lang.String escapeJava(java.lang.String string)
Escapes a string using java rules.
-
unescapeJava
public static java.lang.String unescapeJava(java.lang.String str)
Unescapes a string using java rules.
-
-