Package jodd.util
Class StringUtil
java.lang.Object
jodd.util.StringUtil
String utilities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcapitalize(String str) Capitalizes a string, changing the first letter to upper case.private static StringchangeFirstCharacterCase(boolean capitalize, String string) Internal method for changing the first character case.static StringcompressChars(String s, char c) Compress multiple occurrences of given char into one appearance.static booleancontainsOnlyDigits(CharSequence string) Returnstrueif string contains only digits.static booleanReturnstrueif stringcontains only digitsor signs plus or minus.static booleancontainsOnlyWhitespaces(CharSequence string) Returnstrueif string contains only white spaces.static StringconvertCharset(String source, Charset sourceCharset, Charset newCharset) Converts string charset.static StringconvertTabsToSpaces(String line, int tabWidth) Converts all tabs on a line to spaces according to the provided tab width.static intstatic intstatic intCounts substring occurrences in a source string.static intstatic intcountIgnoreCase(String source, String sub) Count substring occurrences in a source string, ignoring case.static StringCrops string by setting empty strings tonull.static voidCrops all elements of string array.static StringcutBetween(String string, String left, String right) Cuts a string between two other strings.static StringcutFromIndexOf(String string, char c) Cuts the string from the first index of provided char to the end.static StringcutFromIndexOf(String string, String substring) Cuts the string from the first index of provided substring to the end.static StringCuts prefix if exists.static StringCuts sufix if exists.static StringcutSurrounding(String string, String fix) static StringcutSurrounding(String string, String prefix, String suffix) Removes surrounding prefix and suffixes.static StringcutToIndexOf(String string, char c) Cuts the string from beginning to the first index of provided char.static StringcutToIndexOf(String string, String substring) Cuts the string from beginning to the first index of provided substring.static Stringdecapitalize(String name) Utility method to take a string and convert it to normal Java variable name capitalization.static chardetectQuoteChar(String str) Detects quote character or return 0.static booleanendsWithChar(String s, char c) Returns if string ends with provided character.static booleanendsWithIgnoreCase(String src, String subS) Tests if this string ends with the specified suffix.static intendsWithOne(String src, String... dest) Checks if string ends with at least one string from the provided array.static intendsWithOneIgnoreCase(String src, String... dest) Checks if string ends with at least one string from the provided array.static booleanCompares two string arrays.static booleanCompares 2 strings.static booleanequalsIgnoreCase(String[] as, String[] as1) Compares two string arrays.static intCompares string with at least one from the provided array.static intequalsOneIgnoreCase(String src, String... dest) Compares string with at least one from the provided array, ignoring case.static StringescapeJava(String string) Escapes a string using java rules.static StringfindCommonPrefix(String... strings) Finds common prefix for several strings.static StringfromCamelCase(String input, char separator) Changes CamelCase string to lower case words separated by provided separator character.static StringExecutes function on a string if notnull.static intFinds the first occurrence of a character in the given source but within limited range (start, end].static int[]Finds the very first index of a substring from the specified array.static int[]Finds the very first index of a substring from the specified array.static intFinds first occurrence of a substring in the given source but within limited range [start, end).static intindexOfChars(String string, char[] chars) static intindexOfChars(String string, char[] chars, int startindex) Returns the very first index of any char from provided string, starting from specified index offset.static intindexOfChars(String string, String chars) static intindexOfChars(String string, String chars, int startindex) Returns the very first index of any char from provided string, starting from specified index offset.static intindexOfIgnoreCase(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(String src, String subS) Finds first index of a substring in the given source string with ignored case.static int[]indexOfIgnoreCase(String s, String... arr) Finds the very first index of a substring from the specified array.static int[]indexOfIgnoreCase(String s, String[] arr, int start) Finds the very first index of a substring from the specified array.static intindexOfIgnoreCase(String src, String subS, int startIndex) Finds first index of a substring in the given source string with ignored case.static intindexOfIgnoreCase(String src, String sub, int startIndex, int endIndex) Finds first index of a substring in the given source string and range with ignored case.static intindexOfNonWhitespace(String string) static intindexOfNonWhitespace(String string, int startindex) static intindexOfNonWhitespace(String string, int startindex, int endindex) static int[]indexOfRegion(String string, String leftBoundary, String rightBoundary) static int[]indexOfRegion(String string, String leftBoundary, String rightBoundary, char escape) static int[]indexOfRegion(String string, String leftBoundary, String rightBoundary, char escape, int offset) Returns indexes of the first string region.static int[]indexOfRegion(String string, String leftBoundary, String rightBoundary, int offset) Returns indexes of the first region without escaping character.static intindexOfUnescapedChar(String src, char sub, char escapeChar) static intindexOfUnescapedChar(String src, char sub, char escapeChar, int startIndex) static intindexOfWhitespace(String string) Returns first index of a whitespace character.static intindexOfWhitespace(String string, int startindex) static intindexOfWhitespace(String string, int startindex, int endindex) Returns first index of a whitespace character, starting from specified index offset.static Stringstatic StringInserts a string on provided offset.static booleanisAllBlank(String... strings) Determines if string array contains just blank strings.static booleanisAllEmpty(String... strings) Determines if string array contains empty strings.static booleanisBlank(CharSequence string) Determines if a string is blank (nullorcontainsOnlyWhitespaces(CharSequence)).static booleanisCharAtEqual(String string, int index, char charToCompare) Safely compares provided char with char on given location.static booleanisCharAtEscaped(String src, int ndx, char escapeChar) Returnstrueif character at provided index position is escaped by escape character.static booleanisEmpty(CharSequence string) Determines if a string is empty (nullor zero-length).static booleanisNotBlank(CharSequence string) Determines if string is not blank.static booleanisNotEmpty(CharSequence string) Determines if a string is not empty.static booleanisSubstringAt(String string, String substring, int offset) Returnstrueif substring exist at given offset in a string.static StringJoins an array of objects into one string without separators.static StringJoins an array of objects into one string with separator.static StringJoins an array of objects into one string with separator.static Stringjoin(Collection collection, char separator) Joins an collection of objects into one string with separator.static Stringjoin(Collection collection, String separator) static intlastIndexOf(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(String s, String... arr) Finds the very last index of a substring from the specified array.static int[]lastIndexOf(String s, String[] arr, int fromIndex) Finds the very last index of a substring from the specified array.static intlastIndexOf(String src, 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(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(String s, String subS) Finds last index of a substring in the given source string with ignored case.static int[]lastIndexOfIgnoreCase(String s, String... arr) Finds the very last index of a substring from the specified array.static int[]lastIndexOfIgnoreCase(String s, String[] arr, int fromIndex) Finds the very last index of a substring from the specified array.static intlastIndexOfIgnoreCase(String src, String subS, int startIndex) Finds last index of a substring in the given source string with ignored case.static intlastIndexOfIgnoreCase(String src, String sub, int startIndex, int endIndex) Finds last index of a substring in the given source string with ignored case in specified range.static intstatic intlastIndexOfNonWhitespace(String src, int startIndex) static intlastIndexOfNonWhitespace(String src, int startIndex, int endIndex) static intstatic intlastIndexOfWhitespace(String src, int startIndex) Returns last index of a whitespace.static intlastIndexOfWhitespace(String src, int startIndex, int endIndex) Returns last index of a whitespace.static StringmaxCommonPrefix(String one, String two) Returns max common prefix of two strings.static StringInserts prefix if doesn't exist.static StringRemoves a single character from string.static StringRemoves all substring occurrences from the string.static StringremoveChars(String src, char... chars) Removes set of characters from string.static StringremoveChars(String src, String chars) Removes all characters contained in provided string.static StringremoveQuotes(String string) Removes starting and ending single or double quotes.static Stringrepeat(char c, int count) static StringCreates a new string that contains the provided string a number of times.static StringReplaces many substring at once.static StringReplaces all occurrences of a certain pattern in a string with a replacement string.static StringreplaceChar(String s, char sub, char with) Replaces all occurrences of a character in a string.static StringreplaceChars(String s, char[] sub, char[] with) Replaces all occurrences of a characters in a string.static StringreplaceFirst(String s, char sub, char with) Replaces the very first occurrence of a character in a string.static StringreplaceFirst(String s, String sub, String with) Replaces the very first occurrence of a substring with supplied string.static StringreplaceIgnoreCase(String s, String[] sub, String[] with) Replaces many substring at once.static StringreplaceLast(String s, char sub, char with) Replaces the very last occurrence of a character in a string.static StringreplaceLast(String s, String sub, String with) Replaces the very last occurrence of a substring with supplied string.static StringReverse a string.static StringShorten string to given length.static String[]Splits a string in several parts (tokens) that are separated by delimiter.static String[]Splits a string in several parts (tokens) that are separated by single delimiter characters.static String[]Splits a string in several parts (tokens) that are separated by delimiter characters.static String[]Splits a string in several parts (tokens) that are separated by delimiter characters.static booleanstartsWithChar(String s, char c) Returns if string starts with given character.static booleanstartsWithIgnoreCase(String src, String subS) Tests if this string starts with the specified prefix with ignored case.static booleanstartsWithIgnoreCase(String src, 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(String src, String... dest) Checks if string starts with at least one string from the provided array.static intstartsWithOneIgnoreCase(String src, String... dest) Checks if string starts with at least one string from the provided array.static StringStrips leading and trailing char from given string.static StringstripFromChar(String string, char c) Strips everything from the first appearance of given char.static StringstripLeadingChar(String string, char c) Strips leading char if string starts with one.static StringstripToChar(String string, char c) Strips everything up to the first appearance of given char.static StringstripTrailingChar(String string, char c) Strips trailing char if string ends with one.static StringReturns a new string that is a substring of this string.static StringAppends suffix if doesn't exist.static Stringstatic StringSurrounds the string with provided prefix and suffix if such missing from string.static StringMakes a title-cased string from given input.static StringtoCamelCase(String input, boolean firstCharUppercase, char separator) Converts separated string value to CamelCase.static StringtoHexString(byte[] bytes) Converts bytes to hex string.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 StringtoSafeString(Object value) Converts safely an object to a string.static StringConverts safely an object to a string.static String[]toStringArray(Object value) Converts an array object to array of strings, where every element of input array is converted to a string.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 voidTrims array of strings.static StringTrims string and sets tonullif trimmed string is empty.static voidtrimDownAll(String... strings) Trims array of strings where empty strings are set tonull.static StringTrim whitespaces from the left.static StringTrim whitespaces from the right.static StringSets the maximum length of the string.static Stringuncapitalize(String str) Uncapitalizes aString, changing the first letter to lower case.static StringunescapeJava(String str) Unescapes a string using java rules.
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
replace
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
Replaces all occurrences of a character in a string.- Parameters:
s- input stringsub- character to replacewith- character to replace with
-
replaceChars
Replaces all occurrences of a characters in a string.- Parameters:
s- input stringsub- characters to replacewith- characters to replace with
-
replaceFirst
Replaces the very first occurrence of a substring with supplied string.- Parameters:
s- source stringsub- substring to replacewith- substring to replace with
-
replaceFirst
Replaces the very first occurrence of a character in a string.- Parameters:
s- stringsub- char to replacewith- char to replace with
-
replaceLast
Replaces the very last occurrence of a substring with supplied string.- Parameters:
s- source stringsub- substring to replacewith- substring to replace with
-
replaceLast
Replaces the very last occurrence of a character in a string.- Parameters:
s- stringsub- char to replacewith- char to replace with
-
remove
Removes all substring occurrences from the string.- Parameters:
s- source stringsub- substring to remove
-
removeChars
Removes all characters contained in provided string.- Parameters:
src- source stringchars- string containing characters to remove
-
removeChars
Removes set of characters from string.- Parameters:
src- stringchars- characters to remove
-
remove
Removes a single character from string.- Parameters:
string- source stringch- character to remove
-
equals
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
Determines if a string is empty (nullor zero-length). -
isAllEmpty
Determines if string array contains empty strings.- See Also:
-
isBlank
Determines if a string is blank (nullorcontainsOnlyWhitespaces(CharSequence)). -
isNotBlank
Determines if string is not blank. -
isAllBlank
Determines if string array contains just blank strings. -
containsOnlyWhitespaces
Returnstrueif string contains only white spaces. -
containsOnlyDigits
Returnstrueif string contains only digits. -
containsOnlyDigitsAndSigns
Returnstrueif stringcontains only digitsor signs plus or minus. -
isNotEmpty
Determines if a string is not empty. -
toString
Converts safely an object to a string. -
toSafeString
Converts safely an object to a string. If object isnullan empty string is returned. -
toStringArray
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
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
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:
-
changeFirstCharacterCase
Internal method for changing the first character case. -
decapitalize
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
Makes a title-cased string from given input. -
truncate
Sets the maximum length of the string. Longer strings will be simply truncated. -
substring
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
Returnstrueif substring exist at given offset in a string. -
split
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
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
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
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
Compress multiple occurrences of given char into one appearance. -
indexOf
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
Finds the first occurrence of a character in the given source but within limited range (start, end]. -
indexOfIgnoreCase
Finds the first occurrence of a character in the given source but within limited range (start, end]. -
indexOfIgnoreCase
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
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
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:
-
lastIndexOfIgnoreCase
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:
-
lastIndexOfIgnoreCase
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:
-
lastIndexOfIgnoreCase
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
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
Finds last index of a character in the given source string in specified range [end, start] -
lastIndexOfIgnoreCase
Finds last index of a character in the given source string in specified range [end, start] -
lastIndexOfWhitespace
-
lastIndexOfWhitespace
Returns last index of a whitespace. -
lastIndexOfWhitespace
Returns last index of a whitespace. -
lastIndexOfNonWhitespace
-
lastIndexOfNonWhitespace
-
lastIndexOfNonWhitespace
-
startsWithIgnoreCase
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
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
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
Returns if string starts with given character. -
endsWithChar
Returns if string ends with provided character. -
count
Counts substring occurrences in a source string.- Parameters:
source- source stringsub- substring to count- Returns:
- number of substring occurrences
-
count
-
count
-
count
-
countIgnoreCase
Count substring occurrences in a source string, ignoring case.- Parameters:
source- source stringsub- substring to count- Returns:
- number of substring occurrences
-
indexOf
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
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
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
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
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
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
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
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
Compares two string arrays.- Parameters:
as- first string arrayas1- second string array- Returns:
trueif all array elements matches
-
equalsIgnoreCase
Compares two string arrays.- Parameters:
as- first string arrayas1- second string array- Returns:
- true if all array elements matches
-
replace
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
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
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
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
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
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
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
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
- See Also:
-
indexOfChars
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
-
indexOfChars
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
Returns first index of a whitespace character. -
indexOfWhitespace
-
indexOfWhitespace
Returns first index of a whitespace character, starting from specified index offset. -
indexOfNonWhitespace
-
indexOfNonWhitespace
-
indexOfNonWhitespace
-
stripLeadingChar
Strips leading char if string starts with one. -
stripTrailingChar
Strips trailing char if string ends with one. -
stripChar
Strips leading and trailing char from given string. -
stripToChar
Strips everything up to the first appearance of given char. Character IS included in the returned string. -
stripFromChar
Strips everything from the first appearance of given char. Character IS NOT included in the returned string. -
trimAll
Trims array of strings.nullarray elements are ignored. -
trimDownAll
Trims array of strings where empty strings are set tonull.nullelements of the array are ignored.- See Also:
-
trimDown
Trims string and sets tonullif trimmed string is empty. -
crop
Crops string by setting empty strings tonull. -
cropAll
Crops all elements of string array. -
trimLeft
Trim whitespaces from the left. -
trimRight
Trim whitespaces from the right. -
indexOfRegion
- See Also:
-
indexOfRegion
public static int[] indexOfRegion(String string, String leftBoundary, String rightBoundary, int offset) Returns indexes of the first region without escaping character.- See Also:
-
indexOfRegion
public static int[] indexOfRegion(String string, String leftBoundary, String rightBoundary, char escape) - See Also:
-
indexOfRegion
public static int[] indexOfRegion(String string, String leftBoundary, 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
Joins an array of objects into one string without separators. -
join
Joins an array of objects into one string with separator. -
join
Joins an collection of objects into one string with separator. -
join
-
join
Joins an array of objects into one string with separator. -
convertCharset
Converts string charset. If charsets are the same, the same string is returned. -
isCharAtEqual
Safely compares provided char with char on given location. -
surround
- See Also:
-
surround
Surrounds the string with provided prefix and suffix if such missing from string. -
prefix
Inserts prefix if doesn't exist. -
suffix
Appends suffix if doesn't exist. -
cutToIndexOf
Cuts the string from beginning to the first index of provided substring. -
cutToIndexOf
Cuts the string from beginning to the first index of provided char. -
cutFromIndexOf
Cuts the string from the first index of provided substring to the end. -
cutFromIndexOf
Cuts the string from the first index of provided char to the end. -
cutPrefix
Cuts prefix if exists. -
cutSuffix
Cuts sufix if exists. -
cutSurrounding
- See Also:
-
cutSurrounding
Removes surrounding prefix and suffixes. -
cutBetween
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
Returnstrueif character at provided index position is escaped by escape character. -
indexOfUnescapedChar
-
indexOfUnescapedChar
-
insert
-
insert
Inserts a string on provided offset. -
repeat
Creates a new string that contains the provided string a number of times. -
repeat
-
reverse
Reverse a string. -
maxCommonPrefix
Returns max common prefix of two strings. -
findCommonPrefix
Finds common prefix for several strings. Returns an empty string if arguments do not have a common prefix. -
shorten
Shorten string to given length. -
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. 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
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
-
removeQuotes
Removes starting and ending single or double quotes. -
toHexString
Converts bytes to hex string. -
ifNotNull
Executes function on a string if notnull. Otherwise returns an empty string. -
detectQuoteChar
Detects quote character or return 0. -
fromCamelCase
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
Converts separated string value to CamelCase. -
convertTabsToSpaces
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
Escapes a string using java rules. -
unescapeJava
Unescapes a string using java rules.
-