jodd.util
Class StringUtil

java.lang.Object
  extended by jodd.util.StringUtil

public class StringUtil
extends java.lang.Object

Various String utilities.

See Also:
TextUtil

Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String capitalize(java.lang.String str)
          Capitalizes a string, changing the first letter to upper case.
static java.lang.String compressChars(java.lang.String s, char c)
          Compress multiple occurrences of given char into one appearance.
static boolean containsOnlyDigits(java.lang.String string)
          Returns true if string contains only digits.
static boolean containsOnlyWhitespaces(java.lang.String string)
          Returns true if string contains only white spaces.
static java.lang.String convertCharset(java.lang.String source, java.lang.String srcCharsetName, java.lang.String newCharsetName)
          Converts string charset.
static int count(java.lang.String source, char c)
           
static int count(java.lang.String source, char c, int start)
           
static int count(java.lang.String source, java.lang.String sub)
          Counts substring occurrences in a source string.
static int count(java.lang.String source, java.lang.String sub, int start)
           
static int countIgnoreCase(java.lang.String source, java.lang.String sub)
          Count substring occurrences in a source string, ignoring case.
static java.lang.String crop(java.lang.String string)
          Crops string by setting empty strings to null.
static void cropAll(java.lang.String[] strings)
          Crops all elements of string array.
static java.lang.String cutFromIndexOf(java.lang.String string, char c)
          Cuts the string from the first index of provided char to the end.
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.
static java.lang.String cutPrefix(java.lang.String string, java.lang.String prefix)
          Cuts prefix if exists.
static java.lang.String cutSuffix(java.lang.String string, java.lang.String suffix)
          Cuts sufix if exists.
static java.lang.String cutSurrounding(java.lang.String string, java.lang.String fix)
           
static java.lang.String cutSurrounding(java.lang.String string, java.lang.String prefix, java.lang.String suffix)
          Removes surrounding prefix and suffixes.
static java.lang.String cutToIndexOf(java.lang.String string, char c)
          Cuts the string from beginning to the first index of provided char.
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.
static boolean endsWithChar(java.lang.String s, char c)
          Returns if string ends with provided character.
static boolean endsWithIgnoreCase(java.lang.String src, java.lang.String subS)
          Tests if this string ends with the specified suffix.
static int endsWithOne(java.lang.String src, java.lang.String[] dest)
          Checks if string ends with at least one string from the provided array.
static int endsWithOneIgnoreCase(java.lang.String src, java.lang.String[] dest)
          Checks if string ends with at least one string from the provided array.
static boolean equals(java.lang.String[] as, java.lang.String[] as1)
          Compares two string arrays.
static boolean equals(java.lang.String s1, java.lang.String s2)
          Compares 2 strings.
static boolean equalsIgnoreCase(java.lang.String[] as, java.lang.String[] as1)
          Compares two string arrays.
static int equalsOne(java.lang.String src, java.lang.String[] dest)
          Compares string with at least one from the provided array.
static int equalsOneIgnoreCase(java.lang.String src, java.lang.String[] dest)
          Compares string with at least one from the provided array, ignoring case.
static java.lang.String escapeJava(java.lang.String string)
          Escapes a string using java rules.
static java.lang.String findCommonPrefix(java.lang.String... strings)
          Finds common prefix for several strings.
static java.lang.String fromCamelCase(java.lang.String input, char separator)
          Changes CamelCase string to lower case words separated by provided separator character.
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].
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 start)
          Finds the very first index of a substring from the specified array.
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).
static int indexOfChars(java.lang.String string, char[] chars)
           
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.
static int indexOfChars(java.lang.String string, java.lang.String chars)
           
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.
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].
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.
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 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.
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.
static int indexOfNonWhitespace(java.lang.String string)
           
static int indexOfNonWhitespace(java.lang.String string, int startindex)
           
static int indexOfNonWhitespace(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 int indexOfUnescapedChar(java.lang.String src, char sub, char escapeChar)
           
static int indexOfUnescapedChar(java.lang.String src, char sub, char escapeChar, int startIndex)
           
static int indexOfWhitespace(java.lang.String string)
          Returns first index of a whitespace character.
static int indexOfWhitespace(java.lang.String string, int startindex)
           
static int indexOfWhitespace(java.lang.String string, int startindex, int endindex)
          Returns first index of a whitespace character, starting from specified index offset.
static java.lang.String insert(java.lang.String src, java.lang.String insert)
           
static java.lang.String insert(java.lang.String src, java.lang.String insert, int offset)
          Inserts a string on provided offset.
static boolean isAllBlank(java.lang.String... strings)
          Determines if string array contains just blank strings.
static boolean isAllEmpty(java.lang.String... strings)
          Determines if string array contains empty strings.
static boolean isBlank(java.lang.String string)
          Determines if a string is blank (null or containsOnlyWhitespaces(String)).
static boolean isCharAtEqual(java.lang.String string, int index, char charToCompare)
          Safely compares provided char with char on given location.
static boolean isCharAtEscaped(java.lang.String src, int ndx, char escapeChar)
          Returns true if character at provided index position is escaped by escape character.
static boolean isEmpty(java.lang.String string)
          Determines if a string is empty (null or zero-length).
static boolean isNotBlank(java.lang.String string)
          Determines if string is not blank.
static boolean isNotEmpty(java.lang.String string)
          Determines if a string is not empty.
static java.lang.String join(java.lang.Iterable<?> elements, java.lang.String separator)
          Joins list of iterable elements.
static java.lang.String join(java.lang.String... parts)
          Joins an array of strings into one string.
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]
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 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] See indexOf(String, String, int, int) for details about the speed.
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]
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.
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 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.
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.
static int lastIndexOfNonWhitespace(java.lang.String src)
           
static int lastIndexOfNonWhitespace(java.lang.String src, int startIndex)
           
static int lastIndexOfNonWhitespace(java.lang.String src, int startIndex, int endIndex)
           
static int lastIndexOfWhitespace(java.lang.String src)
           
static int lastIndexOfWhitespace(java.lang.String src, int startIndex)
          Returns last index of a whitespace.
static int lastIndexOfWhitespace(java.lang.String src, int startIndex, int endIndex)
          Returns last index of a whitespace.
static java.lang.String maxCommonPrefix(java.lang.String one, java.lang.String two)
          Returns max common prefix of two strings.
static java.lang.String prefix(java.lang.String string, java.lang.String prefix)
          Inserts prefix if doesn't exist.
static java.lang.String remove(java.lang.String string, char ch)
          Removes a single character from string.
static java.lang.String remove(java.lang.String s, java.lang.String sub)
          Removes all substring occurrences from the string.
static java.lang.String removeChars(java.lang.String src, char... chars)
          Removes set of characters from string.
static java.lang.String removeChars(java.lang.String src, java.lang.String chars)
          Removes all characters contained in provided string.
static java.lang.String repeat(char c, int count)
           
static java.lang.String repeat(java.lang.String source, int count)
          Creates a new string that contains the provided string a number of times.
static java.lang.String replace(java.lang.String s, java.lang.String[] sub, java.lang.String[] with)
          Replaces many substring at once.
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.
static java.lang.String replaceChar(java.lang.String s, char sub, char with)
          Replaces all occurrences of a character in a string.
static java.lang.String replaceChars(java.lang.String s, char[] sub, char[] with)
          Replaces all occurrences of a characters in a string.
static java.lang.String replaceFirst(java.lang.String s, char sub, char with)
          Replaces the very first occurrence of a character in a string.
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.
static java.lang.String replaceIgnoreCase(java.lang.String s, java.lang.String[] sub, java.lang.String[] with)
          Replaces many substring at once.
static java.lang.String replaceLast(java.lang.String s, char sub, char with)
          Replaces the very last occurrence of a character in a string.
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.
static java.lang.String reverse(java.lang.String s)
          Reverse a string.
static java.lang.String shorten(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, java.lang.String d)
          Splits a string in several parts (tokens) that are separated by delimiter characters.
static boolean startsWithChar(java.lang.String s, char c)
          Returns if string starts with given character.
static boolean startsWithIgnoreCase(java.lang.String src, java.lang.String subS)
          Tests if this string starts with the specified prefix with ignored case.
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.
static int startsWithOne(java.lang.String src, java.lang.String[] dest)
          Checks if string starts with at least one string from the provided array.
static int startsWithOneIgnoreCase(java.lang.String src, java.lang.String[] dest)
          Checks if string starts with at least one string from the provided array.
static java.lang.String stripLeadingChar(java.lang.String string, char c)
          Strips leading char if string starts with one.
static java.lang.String stripTrailingChar(java.lang.String string, char c)
          Strips trailing char if string ends with one.
static java.lang.String suffix(java.lang.String string, java.lang.String suffix)
          Appends suffix if doesn't exist.
static java.lang.String surround(java.lang.String string, java.lang.String fix)
           
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.
static java.lang.String title(java.lang.String string)
          Makes a title-cased string from given input.
static java.lang.String toCamelCase(java.lang.String input, boolean firstCharUppercase, char separator)
          Converts separated string value to CamelCase.
static java.lang.String toSafeString(java.lang.Object obj)
          Converts safely an object to a string.
static java.lang.String toString(java.lang.Object obj)
          Converts safely an object to a string.
static java.lang.String[] toStringArray(java.lang.Object obj)
          Converts an object to a String Array.
static void trimAll(java.lang.String[] strings)
          Trims array of strings.
static java.lang.String trimDown(java.lang.String string)
          Trims string and sets to null if trimmed string is empty.
static void trimDownAll(java.lang.String[] strings)
          Trims array of strings where empty strings are set to null.
static java.lang.String trimLeft(java.lang.String src)
          Trim whitespaces from the left.
static java.lang.String trimRight(java.lang.String src)
          Trim whitespaces from the right.
static java.lang.String truncate(java.lang.String string, int length)
          Sets the maximum length of the string.
static java.lang.String uncapitalize(java.lang.String str)
          Uncapitalizes a String, changing the first letter to lower case.
static java.lang.String unescapeJava(java.lang.String str)
          Unescapes a string using java rules.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
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 inspected
sub - string pattern to be replaced
with - 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 string
sub - character to replace
with - 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 string
sub - characters to replace
with - 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 string
sub - substring to replace
with - 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 - string
sub - char to replace
with - 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 string
sub - substring to replace
with - 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 - string
sub - char to replace
with - 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 string
sub - 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 string
chars - 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 - string
chars - 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 string
ch - character to remove

equals

public static boolean equals(java.lang.String s1,
                             java.lang.String s2)
Compares 2 strings. If one of the strings is null, false is returned. if both string are null, true is returned.

Parameters:
s1 - first string to compare
s2 - second string
Returns:
true if strings are equal, otherwise false

isEmpty

public static boolean isEmpty(java.lang.String string)
Determines if a string is empty (null or zero-length).


isAllEmpty

public static boolean isAllEmpty(java.lang.String... strings)
Determines if string array contains empty strings.

See Also:
isEmpty(String)

isBlank

public static boolean isBlank(java.lang.String string)
Determines if a string is blank (null or containsOnlyWhitespaces(String)).


isNotBlank

public static boolean isNotBlank(java.lang.String 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.String string)
Returns true if string contains only white spaces.


containsOnlyDigits

public static boolean containsOnlyDigits(java.lang.String string)
Returns true if string contains only digits.


isNotEmpty

public static boolean isNotEmpty(java.lang.String string)
Determines if a string is not empty.


toString

public static java.lang.String toString(java.lang.Object obj)
Converts safely an object to a string. If object is null it will be not converted.


toSafeString

public static java.lang.String toSafeString(java.lang.Object obj)
Converts safely an object to a string. If object is null an empty string is returned.


toStringArray

public static java.lang.String[] toStringArray(java.lang.Object obj)
Converts an object to a String Array.


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 a String, 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, null if null
See Also:
capitalize(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.


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 then StringTokenizer.

Parameters:
src - string to split
delimiter - 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 examine
d - string 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 examine
delimiter - 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 original String.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 examination
sub - substring to find
startIndex - starting index
endIndex - 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 examination
subS - 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 examination
subS - substring to find
startIndex - 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 examination
sub - substring to find
startIndex - starting index from where search begins
endIndex - 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 string
subS - 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 examination
subS - substring to find
startIndex - 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 examine
sub - substring to find
startIndex - starting index
endIndex - 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] See indexOf(String, String, int, int) for details about the speed.

Parameters:
src - source to examine
sub - substring to find
startIndex - starting index
endIndex - 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 test
subS - starting substring
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise.

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 test
subS - starting substring
startIndex - index from where to test
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise.

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 test
subS - suffix
Returns:
true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise.

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 string
sub - 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 string
sub - 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. Returns null if noting found.

Parameters:
s - source string
arr - string array

indexOf

public static int[] indexOf(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. Returns null if noting found.

Parameters:
s - source string
arr - string array
start - 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. Returns null if noting found.

Parameters:
s - source string
arr - 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. Returns null if noting found.

Parameters:
s - source string
arr - string array
start - 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. Returns null if noting found.

Parameters:
s - source string
arr - 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. Returns null if noting found.

Parameters:
s - source string
arr - string array
fromIndex - 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. Returns null if noting found.

Parameters:
s - source string
arr - 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. Returns null if noting found.

Parameters:
s - source string
arr - string array
fromIndex - starting position

equals

public static boolean equals(java.lang.String[] as,
                             java.lang.String[] as1)
Compares two string arrays.

Parameters:
as - first string array
as1 - second string array
Returns:
true if 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 array
as1 - 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 string
sub - substrings array
with - 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 string
sub - substrings array
with - 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, -1 is 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, -1 is 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, -1 is 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, -1 is 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, -1 is 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, -1 is 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 -1 if 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 -1 if 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.


trimAll

public static void trimAll(java.lang.String[] strings)
Trims array of strings. null array elements are ignored.


trimDownAll

public static void trimDownAll(java.lang.String[] strings)
Trims array of strings where empty strings are set to null. null elements of the array are ignored.

See Also:
trimDown(String)

trimDown

public static java.lang.String trimDown(java.lang.String string)
Trims string and sets to null if trimmed string is empty.


crop

public static java.lang.String crop(java.lang.String string)
Crops string by setting empty strings to null.


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)
See Also:
indexOfRegion(String, String, String, int)

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.

See Also:
indexOfRegion(String, String, String, char, int)

indexOfRegion

public static int[] indexOfRegion(java.lang.String string,
                                  java.lang.String leftBoundary,
                                  java.lang.String rightBoundary,
                                  char escape)
See Also:
indexOfRegion(String, String, String, char, int)

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:

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, null is returned.


join

public static java.lang.String join(java.lang.String... parts)
Joins an array of strings into one string.


join

public static java.lang.String join(java.lang.Iterable<?> elements,
                                    java.lang.String separator)
Joins list of iterable elements. Separator string may be null.


convertCharset

public static java.lang.String convertCharset(java.lang.String source,
                                              java.lang.String srcCharsetName,
                                              java.lang.String newCharsetName)
                                       throws java.io.UnsupportedEncodingException
Converts string charset.

Throws:
java.io.UnsupportedEncodingException

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.


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.


isCharAtEscaped

public static boolean isCharAtEscaped(java.lang.String src,
                                      int ndx,
                                      char escapeChar)
Returns true if 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.


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:

toCamelCase

public static java.lang.String toCamelCase(java.lang.String input,
                                           boolean firstCharUppercase,
                                           char separator)
Converts separated string value to CamelCase.


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.



Copyright © 2003-2012 Jodd Team