Package com.webfirmframework.wffweb.util
Class StringUtil
java.lang.Object
com.webfirmframework.wffweb.util.StringUtil
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
cloneArray
(String[] inputArray) To make the clone copy of the given String array.static boolean
containsMinus
(String string) Checks if the given string contains minus (-).static boolean
containsPlus
(String string) Checks if the given string contains plus (+) char.static boolean
containsSpace
(String string) Checks if the given string contains space.static boolean
containsWhitespace
(String string) Checks if the given string contains whitespace.static String
convertSpacesToSingleSpace
(String input) Converts all continues multiple spaces to a single space.static String
convertToSingleSpace
(String input) Converts all continues multiple spaces and new line/lines followed by space/spaces to a single space.static String
Converts all continues multiple whitespaces to a single space.static int
endIndexOf
(String inputString, String startingWith, String endingWith) static int
endIndexOf
(String inputString, String startingWith, String endingWith, int searchFromIndex) static boolean
endsWithColon
(String string) Checks if the last char is a colon (:) charstatic boolean
endsWithSpace
(String string) Checks if the last char is a space charstatic boolean
endsWithWhitespace
(String value) static String[]
getAllSubstrings
(String inputString, String startingWith, String endingWith) gets all substrings as an array which starts and ends with the given values.
Note:- it will never return null instead it will return an empty array (having length zero).static String
getFirstSubstring
(String inputString, String startingWith, String endingWith) gets the first substring which starts and ends with the given values.static String
getFirstSubstring
(String inputString, String startingWith, String endingWith, int searchFromIndex) gets the first substring which starts and ends with the given values.static boolean
static boolean
static boolean
static String
Eg:static String
Eg:static String
join
(char delimiter, Collection<String> items) Eg:static String
removeSpaces
(String input) Removes all spaces from the string.static String
removeWhitespaces
(String input) Removes all whitespaces from the string.static String
static String
static String[]
static String[]
static String[]
splitByAny
(String string, int[] delims) static String[]
splitByColon
(String string) Splits the given string by colon (:).static String[]
splitByComma
(String string) Splits the given string by comma (,).static String[]
splitBySemicolon
(String string) Splits the given string by semicolon (;).static String[]
splitBySpace
(String string) Splits the given string by space.static int[][]
startAndEndIndexesOf
(String inputString, String startingWith, String endingWith) gets all start and end indexes as an array of array which start and end with the given values.
Note:- it will never return null instead it will return an empty array (having length zero).static int[]
startIndexAndEndIndexOf
(String inputString, String startingWith, String endingWith) static int[]
startIndexAndEndIndexOf
(String inputString, String startingWith, String endingWith, int searchFromIndex) static int
startIndexOf
(String inputString, String startingWith, String endingWith) static int
startIndexOf
(String inputString, String startingWith, String endingWith, int searchFromIndex) static boolean
startsWithSpace
(String string) Checks if the first char is a space charstatic boolean
startsWithWhitespace
(String value) static String
Removes the trailing and leading whitespaces
-
Method Details
-
convertToSingleSpace
Converts all continues multiple spaces and new line/lines followed by space/spaces to a single space.- Parameters:
input
- the string to convert- Returns:
- the converted string having a single space in between characters.
- Since:
- 1.0.0
-
convertSpacesToSingleSpace
Converts all continues multiple spaces to a single space.- Parameters:
input
- the string to convert- Returns:
- the converted string having a single space in between characters.
- Since:
- 3.0.15 it is unicode aware
-
convertWhitespacesToSingleSpace
Converts all continues multiple whitespaces to a single space. Please know that new line and tab are also considered as whitespace.- Parameters:
input
- the string to convert- Returns:
- the converted string having a single space in between characters.
- Since:
- 3.0.15 it is unicode aware.
-
removeSpaces
Removes all spaces from the string.- Parameters:
input
-- Returns:
- the string without spaces.
- Since:
- 3.0.15 it is unicode aware.
-
removeWhitespaces
Removes all whitespaces from the string. New line and tab are also whiltespace.- Parameters:
input
-- Returns:
- the string without spaces.
- Since:
- 3.0.15 it is unicode aware.
-
getFirstSubstring
gets the first substring which starts and ends with the given values.- Parameters:
inputString
- the string from which the substring will be extracted.startingWith
- to match the starting substringendingWith
- to match the ending substring- Returns:
- the substring which starts and ends with the given
startingWith
andendingWith
values. Or returns null if it doesn't contain. - Since:
- 1.0.0
-
getFirstSubstring
public static String getFirstSubstring(String inputString, String startingWith, String endingWith, int searchFromIndex) gets the first substring which starts and ends with the given values.- Parameters:
inputString
- the string from which the substring will be extracted.startingWith
- to match the starting substringendingWith
- to match the ending substringsearchFromIndex
- the starting index from where the substring should be searched.- Returns:
- the substring which starts and ends with the given
startingWith
andendingWith
values. Or returns null if it doesn't contain. - Since:
- 1.0.0
-
getAllSubstrings
gets all substrings as an array which starts and ends with the given values.
Note:- it will never return null instead it will return an empty array (having length zero).final String[] allSubstrings = getAllSubstrings("abcd", "ab", "cd"); for (String each : allSubstrings) { System.out.println(each); } the output will be : abcd
- Parameters:
inputString
- the string from which the substrings will be extracted.startingWith
- to match the starting substringendingWith
- to match the ending substring- Returns:
- the array of substrings which contains strings starting and ending
with the given
startingWith
andendingWith
values. Or returns an empty array (i.e an array having length zero) if it doesn't contain. - Since:
- 1.0.0
-
startIndexOf
- Parameters:
inputString
- the string from the index should be found.startingWith
- the substring to check whether it comes in the given inputString beforeendingWith
substring.endingWith
- the substring to check whether it comes in the given inputString afterstartingWith
substring.- Returns:
- the index of
startingWith
substring if the giveninputString
contains a substring starting withstartingWith
string and ending withendingWith
string, otherwise returns -1. - Since:
- 1.0.0
-
endIndexOf
- Parameters:
inputString
- the string from the index should be found.startingWith
- the substring to check whether it comes in the given inputString beforeendingWith
substring.endingWith
- the substring to check whether it comes in the given inputString afterstartingWith
substring.- Returns:
- the index of
endingWith
substring if the giveninputString
contains a substring starting withstartingWith
string and ending withendingWith
string, otherwise returns -1. - Since:
- 1.0.0
-
startIndexOf
public static int startIndexOf(String inputString, String startingWith, String endingWith, int searchFromIndex) - Parameters:
inputString
- the string from the index should be found.startingWith
- the substring to check whether it comes in the given inputString beforeendingWith
substring.endingWith
- the substring to check whether it comes in the given inputString afterstartingWith
substring.searchFromIndex
- the starting index from where the substring should be searched.- Returns:
- the index of
startingWith
substring if the giveninputString
contains a substring starting withstartingWith
string and ending withendingWith
string, otherwise returns -1. - Since:
- 1.0.0
-
endIndexOf
public static int endIndexOf(String inputString, String startingWith, String endingWith, int searchFromIndex) - Parameters:
inputString
- the string from the index should be found.startingWith
- the substring to check whether it comes in the given inputString beforeendingWith
substring.endingWith
- the substring to check whether it comes in the given inputString afterstartingWith
substring.searchFromIndex
- the starting index from where the substring should be searched.- Returns:
- the index of
endingWith
substring if the giveninputString
contains a substring starting withstartingWith
string and ending withendingWith
string, otherwise returns -1. - Since:
- 1.0.0
-
startIndexAndEndIndexOf
public static int[] startIndexAndEndIndexOf(String inputString, String startingWith, String endingWith) - Parameters:
inputString
- the string from the index should be found.startingWith
- the substring to check whether it comes in the given inputString beforeendingWith
substring.endingWith
- the substring to check whether it comes in the given inputString afterstartingWith
substring.- Returns:
- an array containing the index of
startingWith
substring if the giveninputString
contains a substring starting withstartingWith
string and ending withendingWith
string, otherwise returns an empty array. - Since:
- 1.0.0
-
startIndexAndEndIndexOf
public static int[] startIndexAndEndIndexOf(String inputString, String startingWith, String endingWith, int searchFromIndex) - Parameters:
inputString
- the string from the index should be found.startingWith
- the substring to check whether it comes in the given inputString beforeendingWith
substring.endingWith
- the substring to check whether it comes in the given inputString afterstartingWith
substring.searchFromIndex
- the starting index from where the substring should be searched.- Returns:
- an array containing the index of
startingWith
substring if the giveninputString
contains a substring starting withstartingWith
string and ending withendingWith
string, otherwise returns an empty array. - Since:
- 1.0.0
-
startAndEndIndexesOf
public static int[][] startAndEndIndexesOf(String inputString, String startingWith, String endingWith) gets all start and end indexes as an array of array which start and end with the given values.
Note:- it will never return null instead it will return an empty array (having length zero).final int[][] startAndEndIndexesOf = startAndEndIndexesOf( "121 131 141 151 161 171 181 191 101", "1", "1"); for (final int[] startIndexAndEndIndex : startAndEndIndexesOf) { System.out.println(startIndexAndEndIndex[0] + " - " + startIndexAndEndIndex[1]); } the output will be : 0 - 3 4 - 7 8 - 11 12 - 15 16 - 19 20 - 23 24 - 27 28 - 31 32 - 35 int[] startIndexAndEndIndex = startAndEndIndexesOf[0]; // 1, 2 etc.. System.out.println(startIndexAndEndIndex[0] + " - " + startIndexAndEndIndex[1]); the output will be : 0 - 3
- Parameters:
inputString
- the string from which the substrings will be extracted.startingWith
- to match the starting substringendingWith
- to match the ending substring- Returns:
- the array of substrings which contains strings starting and ending
with the given
startingWith
andendingWith
values. Or returns an empty array (i.e an array having length zero) if it doesn't contain. - Since:
- 1.0.0
-
cloneArray
To make the clone copy of the given String array. This method is faster than the clone method of String array.- Parameters:
inputArray
-- Returns:
- the cloned array of the given string array.
- Since:
- 1.0.0
-
isEqual
- Returns:
- true if all strings are equal or null.
- Since:
- 1.0.0
-
isEqual
- Returns:
- true if two strings are equal or null.
- Since:
- 1.0.0
-
startsWithWhitespace
- Parameters:
value
-- Returns:
- true if the given value is starting with a white space
- Since:
- 2.1.8 initial implementation., 3.0.15 unicode aware.
-
endsWithWhitespace
- Parameters:
value
-- Returns:
- true if the given value is ending with a white space
- Since:
- 2.1.8 initial implementation., 3.0.15 unicode aware.
-
split
- Parameters:
string
- the string to split.delim
- to by which the given string to be split.- Returns:
- the array of strings split by the given char.
- Since:
- 3.0.0 public, 3.0.15 unicode aware.
-
split
- Parameters:
string
- the string to split.delim
- to by which the given string to be split. It is the code point value of char.- Returns:
- the array of strings split by the given char.
- Since:
- 3.0.15
-
splitBySpace
Splits the given string by space.- Parameters:
string
-- Returns:
- the array of strings
- Since:
- 2.1.15
-
splitByComma
Splits the given string by comma (,).- Parameters:
string
-- Returns:
- the array of strings
- Since:
- 2.1.15
-
splitBySemicolon
Splits the given string by semicolon (;).- Parameters:
string
-- Returns:
- the array of strings
- Since:
- 2.1.15
-
splitByColon
Splits the given string by colon (:).- Parameters:
string
-- Returns:
- the array of strings
- Since:
- 2.1.15
-
endsWithSpace
Checks if the last char is a space char- Parameters:
string
-- Returns:
- true if the last character is a space char
- Since:
- 2.1.15
-
endsWithColon
Checks if the last char is a colon (:) char- Parameters:
string
-- Returns:
- true if the last character is a colon (:) char
- Since:
- 2.1.15
-
startsWithSpace
Checks if the first char is a space char- Parameters:
string
-- Returns:
- true if the first character is a space char
- Since:
- 2.1.15
-
containsSpace
Checks if the given string contains space.- Parameters:
string
-- Returns:
- true if the given string contains space char.
- Since:
- 2.1.15
-
containsWhitespace
Checks if the given string contains whitespace.- Parameters:
string
-- Returns:
- true if the given string contains space char.
- Since:
- 3.0.1 initial implementation., 3.0.15 it is unicode aware.
-
containsMinus
Checks if the given string contains minus (-).- Parameters:
string
-- Returns:
- true if the given string contains minus (-) char.
- Since:
- 2.1.15
-
containsPlus
Checks if the given string contains plus (+) char.- Parameters:
string
-- Returns:
- true if the given string contains plus (+) char.
- Since:
- 2.1.15
-
join
Eg:String join = StringUtil.join(',', ':', ';', "one", "two", "three", "four"); prints :one,two,three,four;
This method must be faster than Java 8's StringJoiner.- Parameters:
delimiter
-prefix
-suffix
-items
-- Returns:
- String
- Since:
- 3.0.1
-
join
Eg:String join = StringUtil.join(',', "one", "two", "three", "four"); prints one,two,three,four
This method must be faster than Java 8's String.join method.- Parameters:
delimiter
-items
-- Returns:
- String
- Since:
- 3.0.1
-
join
Eg:String join = StringUtil.join(',', "one", "two", "three", "four"); prints one,two,three,four
This method must be faster than Java 8's String.join method.- Parameters:
delimiter
-items
-- Returns:
- String
- Since:
- 3.0.1
-
isBlank
- Parameters:
s
- String to check- Returns:
- true if the given string doesn't contain any char other than whitespace.
- Since:
- 3.0.1 initial implementation., 3.0.15 it is unicode aware.
-
strip
Removes the trailing and leading whitespaces- Parameters:
s
-- Returns:
- the striped string
- Since:
- 3.0.1 initial implementation., 3.0.15 it is unicode aware.
-
replace
- Parameters:
s
- the string for processing.it
- the string for matching.with
- the matching to be replaced with this value.- Returns:
- the processed string
- Since:
- 3.0.15
-
replace
- Parameters:
s
- the string for processing.codePointsSequence
- the array of code points for matching in its sequential order.with
- the matching to be replaced with this value.- Returns:
- the processed string
- Since:
- 3.0.15
-
splitByAny
- Parameters:
string
- the string to split.delims
- to by which the given string to be split. It is the code point values of chars.- Returns:
- the array of strings split by the given charcodes.
- Since:
- 3.0.15
-