Package org.goplanit.utils.misc
Class StringUtils
- java.lang.Object
-
- org.goplanit.utils.misc.StringUtils
-
public class StringUtils extends Object
Some simple string utilities- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isNullOrBlank(String string)
Verify if null or blankstatic String
printBytes(String str, Charset encoding)
print bytes of the Stringstatic String
printChars(String str)
print chars of the Stringstatic String
removeBOM(String value)
A String might have some byte order mark preceding the string (for example InputStreamReader might include this).static String
removeEndingStringWhenPresent(String theString, String endString)
Remove the given string from the end of the string if present and return resultstatic String
removeInitialStringWhenPresent(String theString, String initialString)
Remove the given string from the beginning of the string if present and return resultstatic String[]
splitByAnythingExceptAlphaNumeric(String toSplit)
split string by anything but alpha numeric characters, i.e., a-zA-Z0-9static String
zeroPaddedStringOf(int value, int numPadding)
Value to be converted to string with given zero padding in from
-
-
-
Method Detail
-
removeBOM
public static String removeBOM(String value)
A String might have some byte order mark preceding the string (for example InputStreamReader might include this). These are not visible in the string but do change the underlying bytes compared to a string without this BOM and comparing them will fail despite looking identical. This method will remove the BOM from a copy of this string which is returned.- Parameters:
value
- to remove BOM from- Returns:
- BOM-less copy
-
splitByAnythingExceptAlphaNumeric
public static String[] splitByAnythingExceptAlphaNumeric(String toSplit)
split string by anything but alpha numeric characters, i.e., a-zA-Z0-9- Parameters:
toSplit
- string to split- Returns:
- split string
-
isNullOrBlank
public static boolean isNullOrBlank(String string)
Verify if null or blank- Parameters:
string
- to verify- Returns:
- true when null or blank
-
removeInitialStringWhenPresent
public static String removeInitialStringWhenPresent(String theString, String initialString)
Remove the given string from the beginning of the string if present and return result- Parameters:
theString
- to alterinitialString
- to remove if present- Returns:
- altered string
-
removeEndingStringWhenPresent
public static String removeEndingStringWhenPresent(String theString, String endString)
Remove the given string from the end of the string if present and return result- Parameters:
theString
- to alterendString
- to remove if present- Returns:
- altered string
-
zeroPaddedStringOf
public static String zeroPaddedStringOf(int value, int numPadding)
Value to be converted to string with given zero padding in from- Parameters:
value
- to convertnumPadding
- to apply- Returns:
- created string
-
printBytes
public static String printBytes(String str, Charset encoding)
print bytes of the String- Parameters:
str
- to print bytes forencoding
- to apply- Returns:
- String with printed bytes
-
-