Package com.reportmill.base
Class StringUtils
- java.lang.Object
-
- com.reportmill.base.StringUtils
-
public class StringUtils extends java.lang.Object
This class is a collection of convenient static String utils.
-
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
add(java.lang.String s1, java.lang.String s2)
Adds the two strings together (treats nulls as empty strings).static java.lang.String
add(java.lang.String s1, java.lang.String s2, java.lang.String aSeparator)
Adds the two strings together with separator (treats nulls as empty strings, ommitting sep if either is null).static java.lang.String
delete(java.lang.String aString, java.lang.String aSearch)
Returns the result of deleting from the given string any occurance of the search string.static java.lang.String
deleteIC(java.lang.String aString, java.lang.String aSearch)
Returns the result of deleting from the given string any occurance of the search string (ignores case).static java.lang.String
deleteLastPathComponent(java.lang.String aString)
Returns the given path string minus the last part.static java.lang.String
deletePathExtension(java.lang.String aString)
Returns the given path string minus its extension.static double
doubleValue(java.lang.String aString)
Returns an double value by parsing the given string.static double
doubleValue(java.lang.String aString, int aStart)
Returns an double value by parsing the given string starting at the given index.static boolean
endsWithIC(java.lang.String s1, java.lang.String s2)
Returns whether s1 ends with s2, ignoring case.static boolean
equalsIC(java.lang.String s1, java.lang.String s2)
Returns whether s1 equals s2, ignoring case.static java.lang.String
firstCharLowerCase(java.lang.String aString)
Returns the given string with the first char demoted to lowercase.static java.lang.String
firstCharUpperCase(java.lang.String aString)
Returns the given string with the first char promoted to uppercase.static float
floatValue(java.lang.String aString)
Returns an float value by parsing the given string.static byte[]
getBytes(java.lang.String aString)
Returns the ASCII bytes of the given string (ISO-Latin).static byte[]
getBytes(java.lang.String aString, java.lang.String enc)
Returns the bytes of the given string in the requested char encoding.static java.lang.String
getISOLatinString(byte[] bytes)
Returns a string from the given ASCII bytes.static java.lang.String
getISOLatinString(byte[] bytes, int offset, int length)
Returns a string from the given ASCII bytes (from offset to offset+length).static int
indexOfIC(java.lang.String s1, java.lang.String s2)
Returns the index of search string s2 in given string s1, ignores case.static int
indexOfIC(java.lang.String s1, java.lang.String s2, int start)
Returns the index of search string s2 in given string s1, ignores case and starts at start char index.static int
intValue(java.lang.String aString)
Returns an int value by parsing the given string.static java.lang.String
join(java.lang.Object[] parts, java.lang.String separator)
Allows you to take an array of strings and concatenate them together with a separatorstatic java.lang.String
join(java.lang.Object[] parts, java.lang.String separator, int numElements)
Allows you to take an array of strings and concatenate them together with a separatorstatic java.lang.String
lastPathComponent(java.lang.String aString)
Returns the last part of a path string.static java.lang.String
lastPathComponentNoExt(java.lang.String aString)
Returns the file name of the given path string (minus parent directory and extension).static int
length(java.lang.String aString)
Returns the length of given string (supports null).static java.lang.String
max(java.lang.String s)
String promotion - returns either the given string or empty string (if given string is null).static java.lang.String
min(java.lang.String s)
String demotion - returns either the given string or null (if given string length is zero).static RMRange
nextKeyRangeAfterIndex(java.lang.String aString, int anIndex, RMRange aRange)
Returns the range of the next occurance of @delimited@ text.static java.lang.String
or(java.lang.String s1, java.lang.String s2)
Returns the first non-null string of the two given strings (or null).static java.lang.String
pathExtension(java.lang.String aString)
Returns the extension of the given string (or null if no extension).static java.lang.String
pathExtension2(java.lang.String aString)
Returns the extension of the given string (or the string if no extension).static java.lang.String
replace(java.lang.String s, int start, int end, java.lang.String withString)
Returns the result of replacing in the given string the char range with the with-string.static java.lang.String
replace(java.lang.String aString, java.lang.String search, char replace)
Returns the result of replacing in the given string any occurance of the search string with the replace-char.static java.lang.String
replace(java.lang.String aString, java.lang.String search, java.lang.String replace)
Returns the result of replacing in the given string any occurance of the search string with the replace-string.static java.lang.String
replaceIC(java.lang.String aString, java.lang.String search, java.lang.String replace)
Returns the result of replacing in given string any occurance of search string with replace-string (ignore case).static java.util.List
separate(java.lang.String aString, java.lang.String aSeparator)
Returns a list of parts of given string separated by the given delimiter.static java.util.List
separate(java.lang.String aString, java.lang.String aSeparator, boolean stripLeadingSpaces)
Returns a list of parts of given string separated by the given delimiter, with option to strip leading space.static boolean
startsWithIC(java.lang.String s1, java.lang.String s2)
Returns whether s1 starts with s2, ignoring case.static java.lang.String
toString(float aValue)
Returns a string representation of the given float to (at most) 3 significant digits.static java.lang.String
toString(float aValue, int significantDigits)
Returns a string representation of the given float to the given number of significant digits.static java.lang.String
wrap(java.lang.String aString, int approximateWidth)
Returns string wrapped to approximate width (quick and dirty line wrapping for use in things like option panes).
-
-
-
Method Detail
-
length
public static int length(java.lang.String aString)
Returns the length of given string (supports null).
-
add
public static java.lang.String add(java.lang.String s1, java.lang.String s2)
Adds the two strings together (treats nulls as empty strings).
-
add
public static java.lang.String add(java.lang.String s1, java.lang.String s2, java.lang.String aSeparator)
Adds the two strings together with separator (treats nulls as empty strings, ommitting sep if either is null).
-
min
public static java.lang.String min(java.lang.String s)
String demotion - returns either the given string or null (if given string length is zero).
-
max
public static java.lang.String max(java.lang.String s)
String promotion - returns either the given string or empty string (if given string is null).
-
or
public static java.lang.String or(java.lang.String s1, java.lang.String s2)
Returns the first non-null string of the two given strings (or null).
-
toString
public static java.lang.String toString(float aValue)
Returns a string representation of the given float to (at most) 3 significant digits.
-
toString
public static java.lang.String toString(float aValue, int significantDigits)
Returns a string representation of the given float to the given number of significant digits.
-
nextKeyRangeAfterIndex
public static RMRange nextKeyRangeAfterIndex(java.lang.String aString, int anIndex, RMRange aRange)
Returns the range of the next occurance of @delimited@ text.
-
pathExtension
public static java.lang.String pathExtension(java.lang.String aString)
Returns the extension of the given string (or null if no extension).
-
pathExtension2
public static java.lang.String pathExtension2(java.lang.String aString)
Returns the extension of the given string (or the string if no extension).
-
deletePathExtension
public static java.lang.String deletePathExtension(java.lang.String aString)
Returns the given path string minus its extension.
-
lastPathComponent
public static java.lang.String lastPathComponent(java.lang.String aString)
Returns the last part of a path string.
-
deleteLastPathComponent
public static java.lang.String deleteLastPathComponent(java.lang.String aString)
Returns the given path string minus the last part.
-
lastPathComponentNoExt
public static java.lang.String lastPathComponentNoExt(java.lang.String aString)
Returns the file name of the given path string (minus parent directory and extension).
-
delete
public static java.lang.String delete(java.lang.String aString, java.lang.String aSearch)
Returns the result of deleting from the given string any occurance of the search string.
-
deleteIC
public static java.lang.String deleteIC(java.lang.String aString, java.lang.String aSearch)
Returns the result of deleting from the given string any occurance of the search string (ignores case).
-
replace
public static java.lang.String replace(java.lang.String s, int start, int end, java.lang.String withString)
Returns the result of replacing in the given string the char range with the with-string.
-
replace
public static java.lang.String replace(java.lang.String aString, java.lang.String search, char replace)
Returns the result of replacing in the given string any occurance of the search string with the replace-char.
-
replace
public static java.lang.String replace(java.lang.String aString, java.lang.String search, java.lang.String replace)
Returns the result of replacing in the given string any occurance of the search string with the replace-string.
-
replaceIC
public static java.lang.String replaceIC(java.lang.String aString, java.lang.String search, java.lang.String replace)
Returns the result of replacing in given string any occurance of search string with replace-string (ignore case).
-
separate
public static java.util.List separate(java.lang.String aString, java.lang.String aSeparator)
Returns a list of parts of given string separated by the given delimiter.
-
separate
public static java.util.List separate(java.lang.String aString, java.lang.String aSeparator, boolean stripLeadingSpaces)
Returns a list of parts of given string separated by the given delimiter, with option to strip leading space.
-
intValue
public static int intValue(java.lang.String aString)
Returns an int value by parsing the given string.
-
floatValue
public static float floatValue(java.lang.String aString)
Returns an float value by parsing the given string.
-
doubleValue
public static double doubleValue(java.lang.String aString)
Returns an double value by parsing the given string.
-
doubleValue
public static double doubleValue(java.lang.String aString, int aStart)
Returns an double value by parsing the given string starting at the given index.
-
getBytes
public static byte[] getBytes(java.lang.String aString)
Returns the ASCII bytes of the given string (ISO-Latin).
-
getBytes
public static byte[] getBytes(java.lang.String aString, java.lang.String enc)
Returns the bytes of the given string in the requested char encoding.
-
getISOLatinString
public static java.lang.String getISOLatinString(byte[] bytes)
Returns a string from the given ASCII bytes.
-
getISOLatinString
public static java.lang.String getISOLatinString(byte[] bytes, int offset, int length)
Returns a string from the given ASCII bytes (from offset to offset+length).
-
indexOfIC
public static int indexOfIC(java.lang.String s1, java.lang.String s2)
Returns the index of search string s2 in given string s1, ignores case.
-
indexOfIC
public static int indexOfIC(java.lang.String s1, java.lang.String s2, int start)
Returns the index of search string s2 in given string s1, ignores case and starts at start char index.
-
equalsIC
public static boolean equalsIC(java.lang.String s1, java.lang.String s2)
Returns whether s1 equals s2, ignoring case.
-
endsWithIC
public static boolean endsWithIC(java.lang.String s1, java.lang.String s2)
Returns whether s1 ends with s2, ignoring case.
-
startsWithIC
public static boolean startsWithIC(java.lang.String s1, java.lang.String s2)
Returns whether s1 starts with s2, ignoring case.
-
firstCharUpperCase
public static java.lang.String firstCharUpperCase(java.lang.String aString)
Returns the given string with the first char promoted to uppercase.
-
firstCharLowerCase
public static java.lang.String firstCharLowerCase(java.lang.String aString)
Returns the given string with the first char demoted to lowercase.
-
wrap
public static java.lang.String wrap(java.lang.String aString, int approximateWidth)
Returns string wrapped to approximate width (quick and dirty line wrapping for use in things like option panes).
-
join
public static java.lang.String join(java.lang.Object[] parts, java.lang.String separator)
Allows you to take an array of strings and concatenate them together with a separator- Parameters:
parts
- an array of Stringsseparator
- a string to place between elements- Returns:
-
join
public static java.lang.String join(java.lang.Object[] parts, java.lang.String separator, int numElements)
Allows you to take an array of strings and concatenate them together with a separator- Parameters:
parts
- an array to be conacatenatedseparator
- a string to place between elementsnumElements
- how many to include in the result- Returns:
-
-