Package io.mosip.kernel.core.util
Class StringUtils
- java.lang.Object
-
- io.mosip.kernel.core.util.StringUtils
-
public final class StringUtils extends Object
This class contains methods used for operations on String type data- Since:
- 1.0.0
- Author:
- Sidhant Agarwal
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringabbreviate(String sourceString, int maxWidth)Abbreviates a String using ellipsesstatic Stringabbreviate(String sourceString, int offset, int maxWidth)Abbreviates a String using ellipsesstatic Stringabbreviate(String sourceString, String abbrevMarker, int maxWidth)Abbreviates a String using another given String as replacement markerstatic Stringabbreviate(String sourceString, String abbrevMarker, int offset, int maxWidth)Abbreviates a String using a given replacement markerstatic StringabbreviateMiddle(String sourceString, String middle, int length)Abbreviates a String to the length passed, replacing the middle characters with the supplied replacement Stringstatic StringappendIfMissing(String sourceString, CharSequence suffix, CharSequence... suffixes)Appends the suffix to the end of the string if the string does not already end with any of the suffixesstatic StringappendIfMissingIgnoreCase(String sourceString, CharSequence suffix, CharSequence... suffixes)Appends the suffix to the end of the string if the string does not already end, case insensitive, with any of the suffixesstatic StringcapitalizeFirstLetter(String sourceString)This method capitalizes the first character of the passed parameterstatic Stringchomp(String sourceString)Removes one newline from end of a String if it's there, otherwise leave it alonestatic Stringchop(String sourceString)Remove the last character from a Stringstatic intcompare(String sourceString1, String sourceString2)This method compares two input stringstatic intcompare(String sourceString1, String sourceString2, boolean nullIsLess)This method compares two Strings lexicographicallystatic intcompareIgnoreCase(String sourceString1, String sourceString2)This method compares two Strings lexicographically, ignoring case differencesstatic intcompareIgnoreCase(String sourceString1, String sourceString2, boolean nullIsLess)static booleancontains(CharSequence seq, int searchChar)This method checks if CharSequence contains a search character, handling nullstatic booleancontains(CharSequence seq, CharSequence searchSeq)This method checks if CharSequence contains a search CharSequence, handling nullstatic booleancontainsIgnoreCase(CharSequence sourceString, CharSequence searchStr)This method checks if CharSequence contains a search CharSequence irrespective of case, handling null.static booleancontainsWhitespace(CharSequence seq)This method checks whether the given CharSequence contains any whitespace charactersstatic intcountMatches(CharSequence sourceString, char ch)Counts how many times the char appears in the given stringstatic intcountMatches(CharSequence sourceString, CharSequence sub)Counts how many times the substring appears in the larger stringstatic StringdeleteWhitespace(String sourceString)Deletes all whitespaces from a Stringstatic Stringdifference(String sourceString1, String sourceString2)Compares two Strings, and returns the portion where they differstatic booleanendsWith(CharSequence sourceString, CharSequence suffix)Check if a CharSequence ends with a specified suffixstatic booleanendsWithIgnoreCase(CharSequence sourceString, CharSequence suffix)Case insensitive check if a CharSequence ends with a specified suffixstatic booleanequals(CharSequence charSeq1, CharSequence charSeq2)Compares two CharSequencesstatic booleanequalsIgnoreCase(CharSequence sourceString1, CharSequence sourceString2)Compares two CharSequences ignoring casestatic StringgetDigits(String sourceString)Checks if a String sourceString contains Unicode digits, if yes then concatenate all the digits in sourceString and return it as a Stringstatic intindexOf(CharSequence seq, int searchChar)Returns the index within seq of the first occurrence of the specified characterstatic intindexOf(CharSequence seq, int searchChar, int startPos)Returns the index within seq of the first occurrence of the specified character, starting the search at the specified indexstatic intindexOf(CharSequence seq, CharSequence searchSeq)Finds the first index within a CharSequence, handling nullstatic intindexOf(CharSequence seq, CharSequence searchSeq, int startPos)Finds the first index within a CharSequence, handling nullstatic booleanisAllLowerCase(CharSequence charSeq)Checks if the CharSequence contains only lowercase charactersstatic booleanisAllUpperCase(CharSequence charSeq)Checks if the CharSequence contains only uppercase charactersstatic booleanisAlpha(CharSequence charSeq)Checks if the CharSequence contains only Unicode lettersstatic booleanisAlphanumeric(CharSequence charSeq)Checks if the CharSequence contains only Unicode letters or digitsstatic booleanisAlphanumericSpace(CharSequence charSeq)Checks if the CharSequence contains only Unicode letters, digits or space (' ')static booleanisAlphaSpace(CharSequence charSeq)Checks if the CharSequence contains only Unicode letters and space (' ')static booleanisBlank(CharSequence charSeq)This method checks if a CharSequence is empty (""), null or whitespace onlystatic booleanisEmpty(CharSequence charSeq)This method checks if a CharSequence is empty ("") or nullstatic booleanisMixedCase(CharSequence charSeq)Checks if the CharSequence contains mixed casing of both uppercase and lowercase charactersstatic booleanisNotBlank(CharSequence charSeq)This method checks if a CharSequence is not empty (""), not null and not whitespace onlystatic booleanisNotEmpty(CharSequence charSeq)This method checks if a CharSequence is not empty ("") and not nullstatic booleanisNumeric(CharSequence charSeq)Checks if the CharSequence contains only Unicode digits.static booleanisNumericSpace(CharSequence charSeq)Checks if the CharSequence contains only Unicode digits or space (' ').static booleanisWhitespace(CharSequence charSeq)Checks if the CharSequence contains only whitespacestatic Stringjoin(byte[] array, char separator)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(byte[] array, char separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(char[] array, char separator)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(char[] array, char separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(double[] array, char separator)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(double[] array, char separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(float[] array, char separator)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(float[] array, char separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(int[] array, char separator)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(int[] array, char separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(long[] array, char separator)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(long[] array, char separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(short[] array, char separator)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(short[] array, char separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(Object[] array, char separator)Joins the elements of the provided array into a single String containing the provided list of elementsstatic Stringjoin(Object[] array, char separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elementsstatic intlastIndexOf(CharSequence seq, int searchChar)Returns the index within seq of the last occurrence of the specified characterstatic intlastIndexOf(CharSequence seq, int searchChar, int startPos)Returns the index within seq of the last occurrence of the specified character, searching backward starting at the specified indexstatic intlastIndexOf(CharSequence seq, CharSequence searchSeq)Finds the last index within a CharSequence, handling nullstatic intlastIndexOf(CharSequence seq, CharSequence searchSeq, int startPos)Finds the last index within a CharSequence, handling nullstatic intlength(CharSequence charSeq)String with repeated characterstatic StringlowerCase(String sourceString)CharSequence length or 0 if the CharSequence is nullstatic StringlowerCase(String sourceString, Locale locale)Converts a String to local casestatic StringnormalizeSpace(String sourceString)Returns the argument string with whitespace normalizedstatic Stringoverlay(String sourceString, String overlay, int start, int end)Overlays part of a String with another Stringstatic StringprependIfMissing(String sourceString, CharSequence prefix, CharSequence... prefixes)Prepends the prefix to the start of the string if the string does not already start with any of the prefixesstatic StringprependIfMissingIgnoreCase(String sourceString, CharSequence prefix, CharSequence... prefixes)Prepends the prefix to the start of the string if the string does not already start, case insensitive, with any of the prefixesstatic Stringremove(String sourceString, char remove)Removes all occurrences of a character from within the source stringstatic Stringremove(String sourceString, String remove)Removes all occurrences of a substring from within the source stringstatic StringremoveAll(String text, String regex)Removes each substring of the text String that matches the given regular expressionstatic StringremoveIgnoreCase(String sourceString, String remove)Case insensitive removal of all occurrences of a substring from within the source stringstatic StringremoveLeftChar(String sourceString, int len)Gets the leftmost len characters of a Stringstatic StringremoveMidChar(String sourceString, int pos, int len)Gets len characters from the middle of a Stringstatic StringremovePattern(String source, String regex)Removes each substring of the source String that matches the given regular expressionstatic StringremoveRightChar(String sourceString, int len)Gets the rightmost len characters of a Stringstatic Stringrepeat(char ch, int repeat)Returns padding using the specified delimiter repeated to a given lengthstatic Stringrepeat(String sourceString, int repeat)Repeat a String repeat times to form a new Stringstatic Stringrepeat(String sourceString, String separator, int repeat)Repeat a String repeat times to form a new String, with a String separator injected each timestatic Stringreplace(String text, String searchString, String replacement)Replaces all occurrences of a String within another Stringstatic Stringreplace(String text, String searchString, String replacement, int max)Replaces a String with another String inside a larger String, for the first max values of the search Stringstatic StringreplaceAll(String text, String regex, String replacement)Replaces each substring of the text String that matches the given regular expression with the given replacementstatic StringreplaceChars(String sourceString, char searchChar, char replaceChar)Replaces all occurrences of a character in a String with anotherstatic StringreplaceChars(String sourceString, String searchChars, String replaceChars)Replaces multiple characters in a String in one go(can also be used to delete characters)static StringreplaceIgnoreCase(String text, String searchString, String replacement)Case insensitively replaces all occurrences of a String within another Stringstatic StringreplaceIgnoreCase(String text, String searchString, String replacement, int max)Case insensitively replaces a String with another String inside a larger String, for the first max values of the search Stringstatic StringreplaceOnce(String text, String searchString, String replacement)Replaces a String with another String inside a larger String, oncestatic StringreplaceOnceIgnoreCase(String text, String searchString, String replacement)Case insensitively replaces a String with another String inside a larger String, oncestatic StringreplacePattern(String source, String regex, String replacement)Replaces each substring of the source String that matches the given regular expression with the given replacementstatic Stringreverse(String sourceString)Reverses a Stringstatic StringreverseDelimited(String sourceString, char separatorChar)Reverses a String that is delimited by a specific characterstatic Stringrotate(String sourceString, int shift)Rotate (circular shift) a String of shift charactersstatic String[]split(String sourceString)Splits the provided text into an array, using whitespace as the separatorstatic String[]split(String sourceString, char separatorChar)Splits the provided text into an array, separator specifiedstatic String[]splitByCharacterType(String sourceString)Splits a String by Character typestatic String[]splitByCharacterTypeCamelCase(String sourceString)Splits a String by Character typestatic booleanstartsWith(CharSequence sourceString, CharSequence prefix)Check if a CharSequence starts with a specified prefixstatic booleanstartsWithIgnoreCase(CharSequence sourceString, CharSequence prefix)Case insensitive check if a CharSequence starts with a specified prefixstatic Stringstrip(String sourceString)Strips whitespace from the start and end of a Stringstatic Stringstrip(String sourceString, String stripChars)Strips any of a set of characters from the start and end of a Stringstatic Stringsubstring(String sourceString, int start)Gets a substring from the specified String avoiding exceptions.static Stringsubstring(String sourceString, int start, int end)Gets a substring from the specified String avoiding exceptionsstatic StringsubstringAfter(String sourceString, String separator)Gets the substring after the first occurrence of a separatorstatic StringsubstringBefore(String sourceString, String separator)Gets the substring before the first occurrence of a separatorstatic StringswapCase(String sourceString)Swaps the case of a String changing upper and title case to lower case, and lower case to upper casestatic Stringtrim(String sourceString)This method removes control characters (char is less than= 32) from both ends of this String, handling null by returning nullstatic Stringtruncate(String sourceString, int maxWidth)Truncates a Stringstatic Stringtruncate(String sourceString, int offset, int maxWidth)Truncates a Stringstatic Stringuncapitalize(String sourceString)Uncapitalizes a String, changing the first character to lower casestatic Stringunwrap(String sourceString, char wrapChar)Unwraps a given string from a characterstatic Stringunwrap(String sourceString, String wrapToken)Unwraps a given string from anther stringstatic StringupperCase(String sourceString)CharSequence length or 0 if the CharSequence is nullstatic StringupperCase(String sourceString, Locale locale)Converts a String to upper casestatic Stringwrap(String sourceString, char wrapWith)Wraps a string with a charstatic Stringwrap(String sourceString, String wrapWith)Wraps a String with another Stringstatic StringwrapIfMissing(String sourceString, char wrapWith)Wraps a string with a char if that char is missing from the start or end of the given stringstatic StringwrapIfMissing(String sourceString, String wrapWith)Wraps a string with a string if that string is missing from the start or end of the given string
-
-
-
Method Detail
-
capitalizeFirstLetter
public static String capitalizeFirstLetter(String sourceString)
This method capitalizes the first character of the passed parameter- Parameters:
sourceString- input string- Returns:
- String changing the first character to UpperCase
-
compare
public static int compare(String sourceString1, String sourceString2)
This method compares two input string- Parameters:
sourceString1- String valuesourceString2- String value- Returns:
- 0 if sourceString1 is equal to sourceString2 (or both null) is less than 0, if sourceString1 is less than sourceString2 is greater than 0, if sourceString1 is greater than sourceString2
-
compare
public static int compare(String sourceString1, String sourceString2, boolean nullIsLess)
This method compares two Strings lexicographically- Parameters:
sourceString1- String to compare fromsourceString2- String to compare tonullIsLess- whether consider null value less than non-null value- Returns:
- = 0, if sourceString1 is equal to sourceString2 (or both null) is less than 0, if sourceString1 is less than sourceString2 is greater than 0, if sourceString1 is greater than sourceString2
-
compareIgnoreCase
public static int compareIgnoreCase(String sourceString1, String sourceString2)
This method compares two Strings lexicographically, ignoring case differences- Parameters:
sourceString1- String to compare fromsourceString2- String to compare to- Returns:
- = 0, if sourceString1 is equal to sourceString2 (or both null) is less than 0, if sourceString1 is less than sourceString2 is greater than 0, if sourceString1 is greater than sourceString2
-
compareIgnoreCase
public static int compareIgnoreCase(String sourceString1, String sourceString2, boolean nullIsLess)
- Parameters:
sourceString1- String to compare fromsourceString2- String to compare tonullIsLess- whether consider null value less than non-null value- Returns:
- = 0, if sourceString1 is equal to sourceString2 (or both null) is less than 0, if sourceString1 is less than sourceString2 is greater than 0, if sourceString1 is greater than sourceString2
-
contains
public static boolean contains(CharSequence seq, CharSequence searchSeq)
This method checks if CharSequence contains a search CharSequence, handling null- Parameters:
seq- the CharSequence to check, may be nullsearchSeq- the CharSequence to find, may be null- Returns:
- true if the CharSequence contains the search CharSequence false if not or null string input
-
contains
public static boolean contains(CharSequence seq, int searchChar)
This method checks if CharSequence contains a search character, handling null- Parameters:
seq- the CharSequence to check, may be nullsearchChar- the character to find- Returns:
- true if the CharSequence contains the search CharSequence false if not or null string input
-
containsIgnoreCase
public static boolean containsIgnoreCase(CharSequence sourceString, CharSequence searchStr)
This method checks if CharSequence contains a search CharSequence irrespective of case, handling null.- Parameters:
sourceString- the CharSequence to check, may be nullsearchStr- the CharSequence to find, may be null- Returns:
- true if the CharSequence contains the search CharSequence irrespective of case false if not or null string input
-
containsWhitespace
public static boolean containsWhitespace(CharSequence seq)
This method checks whether the given CharSequence contains any whitespace characters- Parameters:
seq- the CharSequence to check (may be null)- Returns:
- true if the CharSequence is not empty and contains at least 1 (breaking) whitespace character false if no whitespace is present
-
isEmpty
public static boolean isEmpty(CharSequence charSeq)
This method checks if a CharSequence is empty ("") or null- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if the CharSequence is empty or null
-
isNotEmpty
public static boolean isNotEmpty(CharSequence charSeq)
This method checks if a CharSequence is not empty ("") and not null- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if the CharSequence is not empty and not null
-
isBlank
public static boolean isBlank(CharSequence charSeq)
This method checks if a CharSequence is empty (""), null or whitespace only- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if the CharSequence is null, empty or whitespace only
-
isNotBlank
public static boolean isNotBlank(CharSequence charSeq)
This method checks if a CharSequence is not empty (""), not null and not whitespace only- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if the CharSequence is not empty and not null and not whitespace only
-
trim
public static String trim(String sourceString)
This method removes control characters (char is less than= 32) from both ends of this String, handling null by returning null- Parameters:
sourceString- the String to be trimmed, may be null- Returns:
- the trimmed string null, if null String input
-
truncate
public static String truncate(String sourceString, int maxWidth)
Truncates a String- Parameters:
sourceString- the String to truncate, may be nullmaxWidth- maximum length of result String, must be positive- Returns:
- truncated String, null if null String input
-
truncate
public static String truncate(String sourceString, int offset, int maxWidth)
Truncates a String- Parameters:
sourceString- the String to check, may be nulloffset- left edge of source StringmaxWidth- maximum length of result String, must be positive- Returns:
- truncated String, null if null String input
-
strip
public static String strip(String sourceString)
Strips whitespace from the start and end of a String- Parameters:
sourceString- the String to remove whitespace from, may be null- Returns:
- the stripped String, null if null String input
-
strip
public static String strip(String sourceString, String stripChars)
Strips any of a set of characters from the start and end of a String- Parameters:
sourceString- the String to remove characters from, may be nullstripChars- the characters to remove, null treated as whitespace- Returns:
- the stripped String null if null String input
-
equals
public static boolean equals(CharSequence charSeq1, CharSequence charSeq2)
Compares two CharSequences- Parameters:
charSeq1- the first CharSequence, may be nullcharSeq2- charSeq2 the second CharSequence, may be null- Returns:
- true if the CharSequences are equal (case-sensitive), or both null
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(CharSequence sourceString1, CharSequence sourceString2)
Compares two CharSequences ignoring case- Parameters:
sourceString1- the first CharSequence, may be nullsourceString2- the second CharSequence, may be null- Returns:
- true if the CharSequence are equal, case insensitive, or both null
-
indexOf
public static int indexOf(CharSequence seq, int searchChar)
Returns the index within seq of the first occurrence of the specified character- Parameters:
seq- the CharSequence to check, may be nullsearchChar- the character to find- Returns:
- the first index of the search character, -1 if no match or null string input
-
indexOf
public static int indexOf(CharSequence seq, int searchChar, int startPos)
Returns the index within seq of the first occurrence of the specified character, starting the search at the specified index- Parameters:
seq- the CharSequence to check, may be nullsearchChar- the character to findstartPos- the start position, negative treated as zero- Returns:
- the first index of the search character (always ≥ startPos), -1 if no match or null string input
-
indexOf
public static int indexOf(CharSequence seq, CharSequence searchSeq)
Finds the first index within a CharSequence, handling null- Parameters:
seq- the CharSequence to check, may be nullsearchSeq- the CharSequence to find, may be null- Returns:
- the first index of the search CharSequence, -1 if no match or null string input
-
indexOf
public static int indexOf(CharSequence seq, CharSequence searchSeq, int startPos)
Finds the first index within a CharSequence, handling null- Parameters:
seq- the CharSequence to check, may be nullsearchSeq- the CharSequence to find, may be nullstartPos- the start position, negative treated as zero- Returns:
- the first index of the search CharSequence (always ≥ startPos), -1 if no match or null string input
-
lastIndexOf
public static int lastIndexOf(CharSequence seq, int searchChar)
Returns the index within seq of the last occurrence of the specified character- Parameters:
seq- the CharSequence to check, may be nullsearchChar- the character to find- Returns:
- the last index of the search character, -1 if no match or null string input
-
lastIndexOf
public static int lastIndexOf(CharSequence seq, int searchChar, int startPos)
Returns the index within seq of the last occurrence of the specified character, searching backward starting at the specified index- Parameters:
seq- the CharSequence to check, may be nullsearchChar- the character to findstartPos- the start position- Returns:
- the last index of the search character (always ≤ startPos), -1 if no match or null string input
-
lastIndexOf
public static int lastIndexOf(CharSequence seq, CharSequence searchSeq)
Finds the last index within a CharSequence, handling null- Parameters:
seq- the CharSequence to check, may be nullsearchSeq- the CharSequence to find, may be null- Returns:
- the last index of the search String, -1 if no match or null string input
-
lastIndexOf
public static int lastIndexOf(CharSequence seq, CharSequence searchSeq, int startPos)
Finds the last index within a CharSequence, handling null- Parameters:
seq- the CharSequence to check, may be nullsearchSeq- the CharSequence to find, may be nullstartPos- the start position, negative treated as zero- Returns:
- the last index of the search CharSequence (always ≤ startPos), -1 if no match or null string input
-
substring
public static String substring(String sourceString, int start)
Gets a substring from the specified String avoiding exceptions.- Parameters:
sourceString- the String to get the substring from, may be nullstart- the position to start from, negative means count back from the end of the String by this many characters- Returns:
- substring from start position, null if null String input
-
substring
public static String substring(String sourceString, int start, int end)
Gets a substring from the specified String avoiding exceptions- Parameters:
sourceString- the String to get the substring from, may be nullstart- the position to start from, negative means count back from the end of the String by this many charactersend- the position to end at (exclusive), negative means count back from the end of the String by this many characters- Returns:
- substring from start position to end position, null if null String input
-
removeLeftChar
public static String removeLeftChar(String sourceString, int len)
Gets the leftmost len characters of a String- Parameters:
sourceString- the String to get the leftmost characters from, may be nulllen- the length of the required String- Returns:
- the leftmost characters, null if null String input
-
removeRightChar
public static String removeRightChar(String sourceString, int len)
Gets the rightmost len characters of a String- Parameters:
sourceString- the String to get the rightmost characters from, may be nulllen- the length of the required String- Returns:
- the rightmost characters, null if null String input
-
removeMidChar
public static String removeMidChar(String sourceString, int pos, int len)
Gets len characters from the middle of a String- Parameters:
sourceString- the String to get the characters from, may be nullpos- the position to start from, negative treated as zerolen- len the length of the required String- Returns:
- the middle characters, null if null String input
-
substringBefore
public static String substringBefore(String sourceString, String separator)
Gets the substring before the first occurrence of a separator- Parameters:
sourceString- the String to get a substring from, may be nullseparator- the String to search for, may be null- Returns:
- the substring before the first occurrence of the separator, null if null String input
-
substringAfter
public static String substringAfter(String sourceString, String separator)
Gets the substring after the first occurrence of a separator- Parameters:
sourceString- the String to get a substring from, may be nullseparator- the String to search for, may be null- Returns:
- substring after the first occurrence of the separator, null if null String input
-
split
public static String[] split(String sourceString)
Splits the provided text into an array, using whitespace as the separator- Parameters:
sourceString- String to parse, may be null- Returns:
- array of parsed Strings, null if null String input
-
split
public static String[] split(String sourceString, char separatorChar)
Splits the provided text into an array, separator specified- Parameters:
sourceString- the String to parse, may be nullseparatorChar- the character used as the delimiter- Returns:
- an array of parsed Strings, null if null String input
-
splitByCharacterType
public static String[] splitByCharacterType(String sourceString)
Splits a String by Character type- Parameters:
sourceString- the String to split, may be null- Returns:
- an array of parsed Strings, null if null String input
-
splitByCharacterTypeCamelCase
public static String[] splitByCharacterTypeCamelCase(String sourceString)
Splits a String by Character type- Parameters:
sourceString- the String to split, may be null- Returns:
- an array of parsed Strings, null if null String input
-
join
public static String join(Object[] array, char separator)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String, null if null array input
-
join
public static String join(long[] array, char separator)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String, null if null array input
-
join
public static String join(int[] array, char separator)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String, null if null array input
-
join
public static String join(short[] array, char separator)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String, null if null array input
-
join
public static String join(byte[] array, char separator)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String, null if null array input
-
join
public static String join(char[] array, char separator)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String, null if null array input
-
join
public static String join(float[] array, char separator)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String, null if null array input
-
join
public static String join(double[] array, char separator)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use- Returns:
- the joined String, null if null array input
-
join
public static String join(Object[] array, char separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to usestartIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String, null if null array input
- Throws:
ArrayIndexOutOfBoundsException- - if startIndex and endIndex are not valid positions
-
join
public static String join(long[] array, char separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to usestartIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String, null if null array input
- Throws:
ArrayIndexOutOfBoundsException- - if startIndex and endIndex are not valid positions
-
join
public static String join(int[] array, char separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to usestartIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String, null if null array input
- Throws:
ArrayIndexOutOfBoundsException- - if startIndex and endIndex are not valid positions
-
join
public static String join(byte[] array, char separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to usestartIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String, null if null array input
- Throws:
ArrayIndexOutOfBoundsException- - if startIndex and endIndex are not valid positions
-
join
public static String join(short[] array, char separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to usestartIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String, null if null array input
- Throws:
ArrayIndexOutOfBoundsException- - if startIndex and endIndex are not valid positions
-
join
public static String join(char[] array, char separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to usestartIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String, null if null array input
- Throws:
ArrayIndexOutOfBoundsException- - if startIndex and endIndex are not valid positions
-
join
public static String join(double[] array, char separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to usestartIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String, null if null array input
- Throws:
ArrayIndexOutOfBoundsException- - if startIndex and endIndex are not valid positions
-
join
public static String join(float[] array, char separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to usestartIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String, null if null array input
- Throws:
ArrayIndexOutOfBoundsException- - if startIndex and endIndex are not valid positions
-
deleteWhitespace
public static String deleteWhitespace(String sourceString)
Deletes all whitespaces from a String- Parameters:
sourceString- the String to delete whitespace from, may be null- Returns:
- the String without whitespaces, null if null String input
-
remove
public static String remove(String sourceString, String remove)
Removes all occurrences of a substring from within the source string- Parameters:
sourceString- the source String to search, may be nullremove- the String to search for and remove, may be null- Returns:
- the substring with the string removed if found, null if null String input
-
removeIgnoreCase
public static String removeIgnoreCase(String sourceString, String remove)
Case insensitive removal of all occurrences of a substring from within the source string- Parameters:
sourceString- the source String to search, may be nullremove- the String to search for (case insensitive) and remove, may be null- Returns:
- the substring with the string removed if found, null if null String input
-
remove
public static String remove(String sourceString, char remove)
Removes all occurrences of a character from within the source string- Parameters:
sourceString- the source String to search, may be nullremove- the char to search for and remove, may be null- Returns:
- the substring with the char removed if found, null if null String input
-
removeAll
public static String removeAll(String text, String regex)
Removes each substring of the text String that matches the given regular expression- Parameters:
text- text to remove from, may be nullregex- the regular expression to which this string is to be matched- Returns:
- the text with any removes processed, null if null String input
- Throws:
PatternSyntaxException- - if the regular expression's syntax is invalid
-
replaceOnce
public static String replaceOnce(String text, String searchString, String replacement)
Replaces a String with another String inside a larger String, once- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for, may be nullreplacement- the String to replace with, may be null- Returns:
- the text with any replacements processed, null if null String input
-
replaceOnceIgnoreCase
public static String replaceOnceIgnoreCase(String text, String searchString, String replacement)
Case insensitively replaces a String with another String inside a larger String, once- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for (case insensitive), may be nullreplacement- the String to replace with, may be null- Returns:
- the text with any replacements processed, null if null String input
-
replacePattern
public static String replacePattern(String source, String regex, String replacement)
Replaces each substring of the source String that matches the given regular expression with the given replacement- Parameters:
source- the source stringregex- the regular expression to which this string is to be matchedreplacement- the string to be substituted for each match- Returns:
- The resulting replaced String
- Throws:
PatternSyntaxException- - if the regular expression's syntax is invalid
-
removePattern
public static String removePattern(String source, String regex)
Removes each substring of the source String that matches the given regular expression- Parameters:
source- the source stringregex- the regular expression to which this string is to be matched- Returns:
- The resulting String
- Throws:
PatternSyntaxException- - if the regular expression's syntax is invalid
-
replaceAll
public static String replaceAll(String text, String regex, String replacement)
Replaces each substring of the text String that matches the given regular expression with the given replacement- Parameters:
text- text to search and replace in, may be nullregex- the regular expression to which this string is to be matchedreplacement- the string to be substituted for each match- Returns:
- the text with any replacements processed, null if null String input
- Throws:
PatternSyntaxException- if the regular expression's syntax is invalid
-
replace
public static String replace(String text, String searchString, String replacement)
Replaces all occurrences of a String within another String- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for, may be nullreplacement- the String to replace it with, may be null- Returns:
- the text with any replacements processed, null if null String input
-
replaceIgnoreCase
public static String replaceIgnoreCase(String text, String searchString, String replacement)
Case insensitively replaces all occurrences of a String within another String- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for (case insensitive), may be nullreplacement- the String to replace it with, may be null- Returns:
- the text with any replacements processed, null if null String input
-
replace
public static String replace(String text, String searchString, String replacement, int max)
Replaces a String with another String inside a larger String, for the first max values of the search String- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for, may be nullreplacement- the String to replace it with, may be nullmax- maximum number of values to replace, or -1 if no maximum- Returns:
- the text with any replacements processed, null if null String input
-
replaceIgnoreCase
public static String replaceIgnoreCase(String text, String searchString, String replacement, int max)
Case insensitively replaces a String with another String inside a larger String, for the first max values of the search String- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for (case insensitive), may be nullreplacement- the String to replace it with, may be nullmax- maximum number of values to replace, or -1 if no maximum- Returns:
- the text with any replacements processed, null if null String input
-
replaceChars
public static String replaceChars(String sourceString, char searchChar, char replaceChar)
Replaces all occurrences of a character in a String with another- Parameters:
sourceString- String to replace characters in, may be nullsearchChar- the character to search for, may be nullreplaceChar- the character to replace, may be null- Returns:
- modified String, null if null string input
-
replaceChars
public static String replaceChars(String sourceString, String searchChars, String replaceChars)
Replaces multiple characters in a String in one go(can also be used to delete characters)- Parameters:
sourceString- String to replace characters in, may be nullsearchChars- a set of characters to search for, may be nullreplaceChars- a set of characters to replace, may be null- Returns:
- modified String, null if null string inputSince:
-
overlay
public static String overlay(String sourceString, String overlay, int start, int end)
Overlays part of a String with another String- Parameters:
sourceString- the String to do overlaying in, may be nulloverlay- the String to overlay, may be nullstart- the position to start overlaying atend- the position to stop overlaying before- Returns:
- overlayed String, null if null String input
-
chomp
public static String chomp(String sourceString)
Removes one newline from end of a String if it's there, otherwise leave it alone- Parameters:
sourceString- the String to chomp a newline from, may be null- Returns:
- String without newline, null if null String input
-
chop
public static String chop(String sourceString)
Remove the last character from a String- Parameters:
sourceString- the String to chop last character from, may be null- Returns:
- String without last character, null if null String input
-
repeat
public static String repeat(String sourceString, int repeat)
Repeat a String repeat times to form a new String- Parameters:
sourceString- the String to repeat, may be nullrepeat- number of times to repeat sourceString, negative treated as zero- Returns:
- a new String consisting of the original String repeated, null if null String input
-
repeat
public static String repeat(String sourceString, String separator, int repeat)
Repeat a String repeat times to form a new String, with a String separator injected each time- Parameters:
sourceString- the String to repeat, may be nullseparator- the String to inject, may be nullrepeat- number of times to repeat sourceString, negative treated as zero- Returns:
- a new String consisting of the original String repeated, null if null String input
-
repeat
public static String repeat(char ch, int repeat)
Returns padding using the specified delimiter repeated to a given length- Parameters:
ch- character to repeatrepeat- number of times to repeat char, negative treated as zeroReturns:- Returns:
- String with repeated character
-
length
public static int length(CharSequence charSeq)
String with repeated character- Parameters:
charSeq- a CharSequence or null- Returns:
- CharSequence length or 0 if the CharSequence is null
-
upperCase
public static String upperCase(String sourceString)
CharSequence length or 0 if the CharSequence is null- Parameters:
sourceString- the String to upper case, may be null- Returns:
- the upper cased String, null if null String input
-
upperCase
public static String upperCase(String sourceString, Locale locale)
Converts a String to upper case- Parameters:
sourceString- the String to upper case, may be nulllocale- the locale that defines the case transformation rules, must not be null- Returns:
- the upper cased String, null if null String inputSince:
-
lowerCase
public static String lowerCase(String sourceString)
CharSequence length or 0 if the CharSequence is null- Parameters:
sourceString- the String to lower case, may be null- Returns:
- the lower cased String, null if null String input
-
lowerCase
public static String lowerCase(String sourceString, Locale locale)
Converts a String to local case- Parameters:
sourceString- the String to local case, may be nulllocale- the locale that defines the case transformation rules, must not be null- Returns:
- the local cased String, null if null String inputSince:
-
uncapitalize
public static String uncapitalize(String sourceString)
Uncapitalizes a String, changing the first character to lower case- Parameters:
sourceString- the String to uncapitalize, may be null- Returns:
- the uncapitalized String, null if null String input
-
swapCase
public static String swapCase(String sourceString)
Swaps the case of a String changing upper and title case to lower case, and lower case to upper case- Parameters:
sourceString- the String to swap case, may be null- Returns:
- the changed String, null if null String input
-
countMatches
public static int countMatches(CharSequence sourceString, CharSequence sub)
Counts how many times the substring appears in the larger string- Parameters:
sourceString- the CharSequence to check, may be nullsub- the substring to count, may be null- Returns:
- the number of occurrences, 0 if either CharSequence is null
-
countMatches
public static int countMatches(CharSequence sourceString, char ch)
Counts how many times the char appears in the given string- Parameters:
sourceString- the CharSequence to check, may be nullch- the char to count- Returns:
- the number of occurrences, 0 if the CharSequence is null
-
isAlpha
public static boolean isAlpha(CharSequence charSeq)
Checks if the CharSequence contains only Unicode letters- Parameters:
charSeq- charSeq the CharSequence to check, may be null- Returns:
- true if only contains letters, and is non-null
-
isAlphaSpace
public static boolean isAlphaSpace(CharSequence charSeq)
Checks if the CharSequence contains only Unicode letters and space (' ')- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if only contains letters and space, and is non-null
-
isAlphanumeric
public static boolean isAlphanumeric(CharSequence charSeq)
Checks if the CharSequence contains only Unicode letters or digits- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if only contains letters or digits, and is non-null
-
isAlphanumericSpace
public static boolean isAlphanumericSpace(CharSequence charSeq)
Checks if the CharSequence contains only Unicode letters, digits or space (' ')- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if only contains letters, digits or space, and is non-null
-
isNumeric
public static boolean isNumeric(CharSequence charSeq)
Checks if the CharSequence contains only Unicode digits. A decimal point is not a Unicode digit and returns false- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if only contains digits, and is non-null
-
isNumericSpace
public static boolean isNumericSpace(CharSequence charSeq)
Checks if the CharSequence contains only Unicode digits or space (' '). A decimal point is not a Unicode digit and returns false- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if only contains digits or space, and is non-null
-
getDigits
public static String getDigits(String sourceString)
Checks if a String sourceString contains Unicode digits, if yes then concatenate all the digits in sourceString and return it as a String- Parameters:
sourceString- the String to extract digits from, may be null- Returns:
- String with only digits, or an empty ("") String if no digits found, or null String if sourceString is null
-
isWhitespace
public static boolean isWhitespace(CharSequence charSeq)
Checks if the CharSequence contains only whitespace- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if only contains whitespace, and is non-null
-
isAllLowerCase
public static boolean isAllLowerCase(CharSequence charSeq)
Checks if the CharSequence contains only lowercase characters- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if only contains lowercase characters, and is non-null
-
isAllUpperCase
public static boolean isAllUpperCase(CharSequence charSeq)
Checks if the CharSequence contains only uppercase characters- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if only contains uppercase characters, and is non-null
-
isMixedCase
public static boolean isMixedCase(CharSequence charSeq)
Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters- Parameters:
charSeq- the CharSequence to check, may be null- Returns:
- true if the CharSequence contains both uppercase and lowercase characters
-
rotate
public static String rotate(String sourceString, int shift)
Rotate (circular shift) a String of shift characters- Parameters:
sourceString- the String to rotate, may be nullshift- number of time to shift (positive : right shift, negative : left shift)- Returns:
- the rotated String, or the original String if shift == 0, or null if null String input
-
reverse
public static String reverse(String sourceString)
Reverses a String- Parameters:
sourceString- the String to reverse, may be null- Returns:
- the reversed String, null if null String input
-
reverseDelimited
public static String reverseDelimited(String sourceString, char separatorChar)
Reverses a String that is delimited by a specific character- Parameters:
sourceString- the String to reverse, may be nullseparatorChar- the separator character to use- Returns:
- the reversed String, null if null String input
-
abbreviate
public static String abbreviate(String sourceString, int maxWidth)
Abbreviates a String using ellipses- Parameters:
sourceString- the String to check, may be nullmaxWidth- maximum length of result String, must be at least 4- Returns:
- abbreviated String, null if null String input
- Throws:
IllegalArgumentException- - if the width is too small
-
abbreviate
public static String abbreviate(String sourceString, int offset, int maxWidth)
Abbreviates a String using ellipses- Parameters:
sourceString- the String to check, may be nulloffset- left edge of source StringmaxWidth- maximum length of result String, must be at least 4- Returns:
- abbreviated String, null if null String input
- Throws:
IllegalArgumentException- - if the width is too small
-
abbreviate
public static String abbreviate(String sourceString, String abbrevMarker, int maxWidth)
Abbreviates a String using another given String as replacement marker- Parameters:
sourceString- the String to check, may be nullabbrevMarker- the String used as replacement markermaxWidth- maximum length of result String, must be at least abbrevMarker.length + 1- Returns:
- abbreviated String, null if null String input
- Throws:
IllegalArgumentException- - if the width is too small
-
abbreviate
public static String abbreviate(String sourceString, String abbrevMarker, int offset, int maxWidth)
Abbreviates a String using a given replacement marker- Parameters:
sourceString- the String to check, may be nullabbrevMarker- the String used as replacement markeroffset- left edge of source StringmaxWidth- maximum length of result String, must be at least 4- Returns:
- abbreviated String, null if null String input
- Throws:
IllegalArgumentException- - if the width is too small
-
abbreviateMiddle
public static String abbreviateMiddle(String sourceString, String middle, int length)
Abbreviates a String to the length passed, replacing the middle characters with the supplied replacement String- Parameters:
sourceString- the String to check, may be nullmiddle- the String to replace the middle characters with, may be nulllength- the length to abbreviate str to- Returns:
- the abbreviated String if the above criteria is met, or the original String supplied for abbreviation
-
difference
public static String difference(String sourceString1, String sourceString2)
Compares two Strings, and returns the portion where they differ- Parameters:
sourceString1- the first String, may be nullsourceString2- the second String, may be null- Returns:
- the portion of sourceString2 where it differs from sourceString1; returns the empty String if they are equal
-
startsWith
public static boolean startsWith(CharSequence sourceString, CharSequence prefix)
Check if a CharSequence starts with a specified prefix- Parameters:
sourceString- the CharSequence to check, may be nullprefix- the prefix to find, may be null- Returns:
- true if the CharSequence starts with the prefix, case sensitive, or both null
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(CharSequence sourceString, CharSequence prefix)
Case insensitive check if a CharSequence starts with a specified prefix- Parameters:
sourceString- the CharSequence to check, may be nullprefix- the prefix to find, may be null- Returns:
- true if the CharSequence starts with the prefix, case insensitive, or both null
-
endsWith
public static boolean endsWith(CharSequence sourceString, CharSequence suffix)
Check if a CharSequence ends with a specified suffix- Parameters:
sourceString- the CharSequence to check, may be nullsuffix- the suffix to find, may be null- Returns:
- true if the CharSequence ends with the suffix, case sensitive, or both null
-
endsWithIgnoreCase
public static boolean endsWithIgnoreCase(CharSequence sourceString, CharSequence suffix)
Case insensitive check if a CharSequence ends with a specified suffix- Parameters:
sourceString- the CharSequence to check, may be nullsuffix- the suffix to find, may be null- Returns:
- true if the CharSequence ends with the suffix, case insensitive, or both null
-
normalizeSpace
public static String normalizeSpace(String sourceString)
Returns the argument string with whitespace normalized- Parameters:
sourceString- the source String to normalize whitespaces from, may be null- Returns:
- the modified string with whitespace normalized, null if null String input
-
appendIfMissing
public static String appendIfMissing(String sourceString, CharSequence suffix, CharSequence... suffixes)
Appends the suffix to the end of the string if the string does not already end with any of the suffixes- Parameters:
sourceString- The stringsuffix- The suffix to append to the end of the stringsuffixes- Additional suffixes that are valid terminators- Returns:
- A new String if suffix was appended, the same string otherwise
-
appendIfMissingIgnoreCase
public static String appendIfMissingIgnoreCase(String sourceString, CharSequence suffix, CharSequence... suffixes)
Appends the suffix to the end of the string if the string does not already end, case insensitive, with any of the suffixes- Parameters:
sourceString- The stringsuffix- The suffix to append to the end of the stringsuffixes- Additional suffixes that are valid terminators- Returns:
- A new String if suffix was appended, the same string otherwise
-
prependIfMissing
public static String prependIfMissing(String sourceString, CharSequence prefix, CharSequence... prefixes)
Prepends the prefix to the start of the string if the string does not already start with any of the prefixes- Parameters:
sourceString- The stringprefix- The prefix to append to the end of the stringprefixes- Additional prefixes that are valid terminators- Returns:
- A new String if suffix was appended, the same string otherwise
-
prependIfMissingIgnoreCase
public static String prependIfMissingIgnoreCase(String sourceString, CharSequence prefix, CharSequence... prefixes)
Prepends the prefix to the start of the string if the string does not already start, case insensitive, with any of the prefixes- Parameters:
sourceString- The stringprefix- The prefix to prepend to the start of the stringprefixes- Additional prefixes that are valid (optional)- Returns:
- A new String if prefix was prepended, the same string otherwise
-
wrap
public static String wrap(String sourceString, char wrapWith)
Wraps a string with a char- Parameters:
sourceString- the string to be wrapped, may be nullwrapWith- the char that will wrap sourceString- Returns:
- the wrapped string, or null if sourceString==null
-
wrap
public static String wrap(String sourceString, String wrapWith)
Wraps a String with another String- Parameters:
sourceString- the String to be wrapper, may be nullwrapWith- the String that will wrap sourceString- Returns:
- wrapped String, null if null String input
-
wrapIfMissing
public static String wrapIfMissing(String sourceString, char wrapWith)
Wraps a string with a char if that char is missing from the start or end of the given string- Parameters:
sourceString- the string to be wrapped, may be nullwrapWith- the char that will wrap sourceString- Returns:
- the wrapped string, or null if sourceString==null
-
wrapIfMissing
public static String wrapIfMissing(String sourceString, String wrapWith)
Wraps a string with a string if that string is missing from the start or end of the given string- Parameters:
sourceString- the string to be wrapped, may be nullwrapWith- the char that will wrap sourceString- Returns:
- the wrapped string, or null if sourceString==null
-
unwrap
public static String unwrap(String sourceString, String wrapToken)
Unwraps a given string from anther string- Parameters:
sourceString- the String to be unwrapped, can be nullwrapToken- the String used to unwrap- Returns:
- unwrapped String or the original string if it is not quoted properly with the wrapToken
-
unwrap
public static String unwrap(String sourceString, char wrapChar)
Unwraps a given string from a character- Parameters:
sourceString- the String to be unwrapped, can be nullwrapChar- the character used to unwrap- Returns:
- unwrapped String or the original string if it is not quoted properly with the wrapChar
-
-