Package snap.util
Class StringUtils
java.lang.Object
snap.util.StringUtils
This class is a collection of convenient static String utils.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Adds the two strings together (treats nulls as empty strings).static String
Adds the two strings together with separator (treats nulls as empty strings, omitting sep if either is null).static int
addWords
(String aString, int aStart, int anEnd, StringBuffer aBuffer, Matcher aMatcher) Adds words from given string and string start/end to given string buffer.static StringBuffer
appendProp
(StringBuffer aSB, String aName, Object aVal) Adds a property name/value to a StringBuffer being configured with multiple comma separated props.static boolean
containsIC
(String[] theStrings, String aString) Returns whether the given string array contains the given string, ignoring case.static String
Returns the result of deleting from the given string any occurrence of the search string.static String
Returns the result of deleting from the given string any occurrence of the search string (ignores case).static double
doubleValue
(String aString) Returns an double value by parsing the given string.static double
doubleValue
(String aString, int aStart) Returns an double value by parsing the given string starting at the given index.static boolean
endsWithIC
(String s1, String s2) Returns whether s1 ends with s2, ignoring case.static boolean
Returns whether s1 equals s2, ignoring case.static String
firstCharLowerCase
(String aString) Returns the given string with the first char demoted to lowercase.static String
firstCharUpperCase
(String aString) Returns the given string with the first char promoted to uppercase.static float
floatValue
(String aString) Returns an float value by parsing the given string.static String
Formats a number with given Decimal format pattern.static String
fromCamelCase
(String aString) Returns a spaced string from a camel case string.static byte[]
Returns the ASCII bytes of the given string (ISO-Latin).static byte[]
Returns the bytes of the given string in the requested char encoding.static String
getISOLatinString
(byte[] bytes) Returns a string from the given ASCII bytes.static String
getISOLatinString
(byte[] bytes, int offset, int length) Returns a string from the given ASCII bytes (from offset to offset+length).static String
getStackTraceString
(Throwable aThrowable) Returns a stack trace string for given exception.static String
getStackTraceString
(Throwable aThrowable, int aDepth) Returns a stack trace string for given exception.static String
getString
(byte[] theBytes) Returns a string for given bytes.static String
Returns a string for given bytes.static String
getStringQuoted
(String aString) Returns a quoted string.static String
getStringSurrounded
(String aString, String aSurroundString, String anEscapeString) Returns a string surrounded by given string.static int
indexOf
(CharSequence theChars, CharSequence theSearch, int aStart) Returns the last index of given search chars in given chars.static int
indexOfIC
(CharSequence s1, CharSequence s2) Returns the index of search string s2 in given string s1, ignores case.static int
indexOfIC
(CharSequence s1, CharSequence s2, int start) Returns the index of search string s2 in given string s1, ignores case and starts at start char index.static int
Returns the index of a given string in the given array, ignoring case.static int
Returns an int value by parsing the given string.static boolean
Returns whether string is null or empty.static String
Returns a joined string given an array and separator.static String
Returns a joined string given a list and separator.static int
lastIndexOf
(CharSequence theChars, CharSequence theSearch) Returns the last index of given search chars in given chars.static int
length
(CharSequence aString) Returns the length of given string (supports null).static long
Returns an int value by parsing the given string.static long
Returns an double value by parsing the given string starting at the given index.static String
String promotion - returns either the given string or empty string (if given string is null).static String
String demotion - returns either the given string or null (if given string length is zero).static String
Returns the first non-null string of the two given strings (or null).static String
Returns the result of replacing in the given string the char range with the with-string.static String
Returns the result of replacing in the given string any occurrence of the search string with the replace-string.static String
Returns the result of replacing in given string any occurrence of search string with replace-string (ignore case).Returns a list of parts of given string separated by the given delimiter.Returns a list of parts of given string separated by the given delimiter, with option to trim space.static boolean
startsWithIC
(String s1, String s2) Returns whether s1 starts with s2, ignoring case.static String
toCamelCase
(String aString) Returns a camel cased string from a string with non-alphanumeric chars.static String
toString
(double aValue) Returns a string representation of the given float to (at most) 3 significant digits.static StringBuffer
Returns a basic toString for given object.static StringBuffer
toStringAdd
(StringBuffer aSB, Object anObj, String... theNames) Adds an attribute to toString string.static StringBuffer
toStringAdd
(StringBuffer aSB, String aName, Object aVal) Adds an attribute to toString string.static String
trimEnd
(CharSequence aStr) Trims the end of a string.static String
trimStart
(CharSequence aStr) Trims the start of a string.static String
Returns a string wrapped on word boundaries.static String
Returns a string wrapped on word boundaries as defined by regex string (eg., whitespace="\\s*", dot="\\.", etc.).
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
isEmpty
Returns whether string is null or empty. -
length
Returns the length of given string (supports null). -
add
Adds the two strings together (treats nulls as empty strings). -
add
Adds the two strings together with separator (treats nulls as empty strings, omitting sep if either is null). -
min
String demotion - returns either the given string or null (if given string length is zero). -
max
String promotion - returns either the given string or empty string (if given string is null). -
or
Returns the first non-null string of the two given strings (or null). -
toString
Returns a string representation of the given float to (at most) 3 significant digits. -
toString
Returns a basic toString for given object. -
toStringAdd
Adds an attribute to toString string. -
toStringAdd
Adds an attribute to toString string. -
appendProp
Adds a property name/value to a StringBuffer being configured with multiple comma separated props. -
trimStart
Trims the start of a string. -
trimEnd
Trims the end of a string. -
delete
Returns the result of deleting from the given string any occurrence of the search string. -
deleteIC
Returns the result of deleting from the given string any occurrence of the search string (ignores case). -
replace
Returns the result of replacing in the given string the char range with the with-string. -
replace
Returns the result of replacing in the given string any occurrence of the search string with the replace-string. -
replaceIC
Returns the result of replacing in given string any occurrence of search string with replace-string (ignore case). -
separate
Returns a list of parts of given string separated by the given delimiter. -
separate
Returns a list of parts of given string separated by the given delimiter, with option to trim space. -
intValue
Returns an int value by parsing the given string. -
longValue
Returns an int value by parsing the given string. -
longValue
Returns an double value by parsing the given string starting at the given index. -
floatValue
Returns an float value by parsing the given string. -
doubleValue
Returns an double value by parsing the given string. -
doubleValue
Returns an double value by parsing the given string starting at the given index. -
getBytes
Returns the ASCII bytes of the given string (ISO-Latin). -
getBytes
Returns the bytes of the given string in the requested char encoding. -
getString
Returns a string for given bytes. -
getString
Returns a string for given bytes. -
getISOLatinString
Returns a string from the given ASCII bytes. -
getISOLatinString
Returns a string from the given ASCII bytes (from offset to offset+length). -
indexOf
Returns the last index of given search chars in given chars. -
lastIndexOf
Returns the last index of given search chars in given chars. -
indexOfIC
Returns the index of search string s2 in given string s1, ignores case. -
indexOfIC
Returns the index of search string s2 in given string s1, ignores case and starts at start char index. -
equalsIC
Returns whether s1 equals s2, ignoring case. -
endsWithIC
Returns whether s1 ends with s2, ignoring case. -
startsWithIC
Returns whether s1 starts with s2, ignoring case. -
firstCharUpperCase
Returns the given string with the first char promoted to uppercase. -
firstCharLowerCase
Returns the given string with the first char demoted to lowercase. -
fromCamelCase
Returns a spaced string from a camel case string. -
toCamelCase
Returns a camel cased string from a string with non-alphanumeric chars. -
wrap
Returns a string wrapped on word boundaries. -
wrap
Returns a string wrapped on word boundaries as defined by regex string (eg., whitespace="\\s*", dot="\\.", etc.). -
addWords
public static int addWords(String aString, int aStart, int anEnd, StringBuffer aBuffer, Matcher aMatcher) Adds words from given string and string start/end to given string buffer. -
join
Returns a joined string given an array and separator. -
join
Returns a joined string given a list and separator. -
indexOfIC
Returns the index of a given string in the given array, ignoring case. -
containsIC
Returns whether the given string array contains the given string, ignoring case. -
getStringQuoted
Returns a quoted string. -
getStringSurrounded
public static String getStringSurrounded(String aString, String aSurroundString, String anEscapeString) Returns a string surrounded by given string. -
getStackTraceString
Returns a stack trace string for given exception. -
getStackTraceString
Returns a stack trace string for given exception. -
formatNum
Formats a number with given Decimal format pattern.
-