Class StringUtils
java.lang.Object
com.inductiveautomation.snap.util.StringUtils
This class is a collection of convenient static String utils.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic StringAdds the two strings together (treats nulls as empty strings).static StringAdds the two strings together with separator (treats nulls as empty strings, omitting sep if either is null).static intaddWords(String aString, int aStart, int anEnd, StringBuffer aBuffer, Matcher aMatcher) Adds words from given string and string start/end to given string buffer.static booleancontainsIC(CharSequence aString1, CharSequence aString2) Returns whether a given string contains a given string, ignoring case.static booleancontainsIC(String[] theStrings, String aString) Returns whether the given string array contains the given string, ignoring case.static StringReturns the result of deleting from the given string any occurrence of the search string.static StringReturns the result of deleting from the given string any occurrence of the search string (ignores case).static doubledoubleValue(String aString) Returns an double value by parsing the given string.static doubledoubleValue(String aString, int aStart) Returns an double value by parsing the given string starting at the given index.static booleanendsWithIC(String s1, String s2) Returns whether s1 ends with s2, ignoring case.static booleanendsWithIC(String s1, String... strings) Returns whether s1 ends with any of the given strings, ignoring case.static booleanReturns whether s1 equals s2, ignoring case.static booleanReturns whether s1 equals any of the given strings, ignoring case.static StringfirstCharLowerCase(String aString) Returns the given string with the first char demoted to lowercase.static StringfirstCharUpperCase(String aString) Returns the given string with the first char promoted to uppercase.static floatfloatValue(String aString) Returns an float value by parsing the given string.static StringfromCamelCase(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 StringgetISOLatinString(byte[] bytes) Returns a string from the given ASCII bytes.static StringgetISOLatinString(byte[] bytes, int offset, int length) Returns a string from the given ASCII bytes (from offset to offset+length).static StringgetPathChild(String aPath, String aChildPath) Returns a path with a filename or relative path added.static StringgetPathExtension(String aPath) Returns the extension of the given string path (everything after last '.').static StringgetPathFileName(String aPath) Returns the file name component of the given string path (everything after last file separator).static intgetPathFileNameIndex(String aPath) Returns the index to the first character of the filename component of the given path.static StringgetPathFileNameSimple(String aPath) Returns the simple file name for a given path (just the file name without extension).static StringgetPathParent(String aPath) Returns the given string path minus the file name component (everything after last file separator).static StringgetPathPeer(String aPath, String aName) Returns a peer path for given path and new filename by stripping filename from given path and using given name.static StringgetPathSimple(String aPath) Returns the given string path minus any extension.static StringgetPathSister(String aPath, String anExtension) Returns a sister path for given path and new extension by stripping extension from path and using given extension.static StringgetPathStandardized(String aPath) Returns the path in a standard, normal format (strips any trailing file separators).static StringgetStackTraceString(Throwable aThrowable) Returns a stack trace string for given exception.static StringgetString(byte[] theBytes) Returns a string for given bytes.static StringReturns a string for given bytes.static StringgetStringQuoted(String aString) Returns a quoted string.static StringgetStringSingleQuoted(String aString) Returns a single quoted string.static StringgetStringSurrounded(String aString, String aSurroundString, String anEscapeString) Returns a string surrounded by given string.static intindexOfIC(CharSequence s1, CharSequence s2) Returns the index of search string s2 in given string s1, ignores case.static intindexOfIC(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 intReturns the index of a given string in the given array, ignoring case.static intReturns an int value by parsing the given string.static booleanReturns whether string is null or empty.static StringAllows you to take an array of strings and concatenate them together with a separatorstatic StringAllows you to take an array of strings and concatenate them together with a separatorstatic intlength(CharSequence aString) Returns the length of given string (supports null).static longReturns an int value by parsing the given string.static longReturns an double value by parsing the given string starting at the given index.static StringString promotion - returns either the given string or empty string (if given string is null).static StringString demotion - returns either the given string or null (if given string length is zero).static StringnextInSequence(String source, String suffix) Turns a string like "myFile" into "myFile-1", and a string like "myFile-2" to "myFile-3", given suffix like "-".static StringReturns the first non-null string of the two given strings (or null).static StringReturns the result of replacing in the given string the char range with the with-string.static StringReturns the result of replacing in the given string any occurrence of the search string with the replace-char.static StringReturns the result of replacing in the given string any occurrence of the search string with the replace-string.static StringReturns 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 booleanstartsWithIC(String s1, String s2) Returns whether s1 starts with s2, ignoring case.static booleanstartsWithIC(String s1, String... strings) Returns whether s1 starts with any of the given strings, ignoring case.static StringtoCamelCase(String aString) Returns a camel cased string from a string with non-alphanumeric chars.static StringtoString(double aValue) Returns a string representation of the given float to (at most) 3 significant digits.static StringTrims the end of a string.static StringReturns a string wrapped on word boundaries.static StringReturns a string wrapped on word boundaries as defined by regex string (eg., whitespace="\\s*", dot="\\.", etc.).
- 
Constructor Details- 
StringUtilspublic StringUtils()
 
- 
- 
Method Details- 
isEmptyReturns whether string is null or empty.
- 
lengthReturns the length of given string (supports null).
- 
addAdds the two strings together (treats nulls as empty strings).
- 
addAdds the two strings together with separator (treats nulls as empty strings, omitting sep if either is null).
- 
minString demotion - returns either the given string or null (if given string length is zero).
- 
maxString promotion - returns either the given string or empty string (if given string is null).
- 
orReturns the first non-null string of the two given strings (or null).
- 
toStringReturns a string representation of the given float to (at most) 3 significant digits.
- 
getPathFileNameReturns the file name component of the given string path (everything after last file separator).
- 
getPathFileNameSimpleReturns the simple file name for a given path (just the file name without extension).
- 
getPathFileNameIndexReturns the index to the first character of the filename component of the given path.
- 
getPathExtensionReturns the extension of the given string path (everything after last '.').
- 
getPathSimpleReturns the given string path minus any extension.
- 
getPathParentReturns the given string path minus the file name component (everything after last file separator).
- 
getPathChildReturns a path with a filename or relative path added.
- 
getPathPeerReturns a peer path for given path and new filename by stripping filename from given path and using given name.
- 
getPathSisterReturns a sister path for given path and new extension by stripping extension from path and using given extension.
- 
getPathStandardizedReturns the path in a standard, normal format (strips any trailing file separators).
- 
trimEndTrims the end of a string.
- 
deleteReturns the result of deleting from the given string any occurrence of the search string.
- 
deleteICReturns the result of deleting from the given string any occurrence of the search string (ignores case).
- 
replaceReturns the result of replacing in the given string the char range with the with-string.
- 
replaceReturns the result of replacing in the given string any occurrence of the search string with the replace-char.
- 
replaceReturns the result of replacing in the given string any occurrence of the search string with the replace-string.
- 
replaceICReturns the result of replacing in given string any occurrence of search string with replace-string (ignore case).
- 
separateReturns a list of parts of given string separated by the given delimiter.
- 
separateReturns a list of parts of given string separated by the given delimiter, with option to trim space.
- 
intValueReturns an int value by parsing the given string.
- 
longValueReturns an int value by parsing the given string.
- 
longValueReturns an double value by parsing the given string starting at the given index.
- 
floatValueReturns an float value by parsing the given string.
- 
doubleValueReturns an double value by parsing the given string.
- 
doubleValueReturns an double value by parsing the given string starting at the given index.
- 
getBytesReturns the ASCII bytes of the given string (ISO-Latin).
- 
getBytesReturns the bytes of the given string in the requested char encoding.
- 
getStringReturns a string for given bytes.
- 
getStringReturns a string for given bytes.
- 
getISOLatinStringReturns a string from the given ASCII bytes.
- 
getISOLatinStringReturns a string from the given ASCII bytes (from offset to offset+length).
- 
indexOfICReturns the index of search string s2 in given string s1, ignores case.
- 
indexOfICReturns the index of search string s2 in given string s1, ignores case and starts at start char index.
- 
containsICReturns whether a given string contains a given string, ignoring case.
- 
equalsICReturns whether s1 equals s2, ignoring case.
- 
equalsICReturns whether s1 equals any of the given strings, ignoring case.
- 
endsWithICReturns whether s1 ends with s2, ignoring case.
- 
endsWithICReturns whether s1 ends with any of the given strings, ignoring case.
- 
startsWithICReturns whether s1 starts with s2, ignoring case.
- 
startsWithICReturns whether s1 starts with any of the given strings, ignoring case.
- 
firstCharUpperCaseReturns the given string with the first char promoted to uppercase.
- 
firstCharLowerCaseReturns the given string with the first char demoted to lowercase.
- 
fromCamelCaseReturns a spaced string from a camel case string.
- 
toCamelCaseReturns a camel cased string from a string with non-alphanumeric chars.
- 
wrapReturns a string wrapped on word boundaries.
- 
wrapReturns a string wrapped on word boundaries as defined by regex string (eg., whitespace="\\s*", dot="\\.", etc.).
- 
addWordspublic 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.
- 
joinAllows you to take an array of strings and concatenate them together with a separator- Parameters:
- parts- an array of Strings
- separator- a string to place between elements
 
- 
joinAllows you to take an array of strings and concatenate them together with a separator- Parameters:
- parts- an array of Strings
- separator- a string to place between elements
 
- 
nextInSequenceTurns a string like "myFile" into "myFile-1", and a string like "myFile-2" to "myFile-3", given suffix like "-".
- 
indexOfICReturns the index of a given string in the given array, ignoring case.
- 
containsICReturns whether the given string array contains the given string, ignoring case.
- 
getStringQuotedReturns a quoted string.
- 
getStringSingleQuotedReturns a single quoted string.
- 
getStringSurroundedpublic static String getStringSurrounded(String aString, String aSurroundString, String anEscapeString) Returns a string surrounded by given string.
- 
getStackTraceStringReturns a stack trace string for given exception.
 
-