public class StringUtilities
extends java.lang.Object
Various static methods helpful for comparing and manipulating strings.
Modifier and Type | Method and Description |
---|---|
static int |
compareStringsThatMayBeIntegers(java.lang.String s1,
java.lang.String s2)
Compare strings based on their integer value of they are both integers,
otherwise their lexicographic order.
|
static int |
compareStringsWithEmbeddedNonZeroPaddedIntegers(java.lang.String s1,
java.lang.String s2)
Compare strings based on the lexicographic order of their values, but accounting for non-zero padded integers.
|
static boolean |
contains(java.lang.String string,
java.lang.String[] substrings)
Does a string contain any one of an array of strings ?
|
static boolean |
containsRegardlessOfCase(java.lang.String string,
java.lang.String[] substrings)
Does a string contain any one of an array of strings regardless of case ?
|
static java.lang.String |
dump(char[] chars)
Create a dump of the decimal offset, hexadecimal values and printable string values of an array of char.
|
static java.lang.String |
dump(java.lang.String s)
Create a dump of the decimal offset, hexadecimal values and printable string values of a String.
|
static java.util.Vector |
getDelimitedValues(java.lang.String string,
java.lang.String delimiter)
Get delimited values from a string.
|
static java.lang.String |
getStringNoLongerThanTruncatedIfNecessary(java.lang.String str,
int wanted) |
static java.lang.String |
padPositiveInteger(java.lang.String str,
int length,
java.lang.Character pad) |
static java.lang.String |
removeLeadingCharacter(java.lang.String src,
char rmchar)
Remove any leading instances of a particular character from a string.
|
static java.lang.String |
removeLeadingOrTrailingWhitespaceOrISOControl(java.lang.String src)
Remove any leading or trailing padding from a string.
|
static java.lang.String |
removeLeadingSpaces(java.lang.String src)
Remove any leading spaces from a string.
|
static java.lang.String |
removeLeadingWhitespaceOrISOControl(java.lang.String src)
Remove any leading instances of whitespace or control characters from a string.
|
static java.lang.String |
removeTrailingCharacter(java.lang.String src,
char rmchar)
Remove any trailing instances of a particular character from a string.
|
static java.lang.String |
removeTrailingSpaces(java.lang.String src)
Remove any trailing spaces from a string.
|
static java.lang.String |
removeTrailingWhitespaceOrISOControl(java.lang.String src)
Remove any trailing instances of whitespace or control characters from a string.
|
static java.lang.String |
replaceAllInWith(java.lang.String string,
java.lang.String oldChars,
java.lang.String newChars)
Replace all listed characters in a string with those listed as replacements.
|
static java.lang.String |
toString(double[] doubleArray) |
static java.lang.String |
toString(java.lang.String[] stringArray) |
static java.lang.String |
toString(java.lang.String[][] stringArrays) |
static java.lang.String |
toUpperCamelCase(java.lang.String string) |
static java.lang.String |
zeroPadPositiveInteger(java.lang.String str,
int length) |
public static final int compareStringsThatMayBeIntegers(java.lang.String s1, java.lang.String s2)
Compare strings based on their integer value of they are both integers, otherwise their lexicographic order.
For example,
"001"
and"1"
would be treated as equal, whilst
"1"
would be considered as occuring before "10"
,
which would not be the case with a simple lexicographic ordering.
s1
- the first of two strings to be compareds2
- the first of two strings to be comparedpublic static final int compareStringsWithEmbeddedNonZeroPaddedIntegers(java.lang.String s1, java.lang.String s2)
Compare strings based on the lexicographic order of their values, but accounting for non-zero padded integers.
Note that the comparison is more complex than a simple lexicographic comparison
of strings (as described in the definition of java.lang.String.compareTo(String)
but rather accounts for embedded non-zero padded integers by treating occurrences of space
delimited integers as integer values rather than strings. For example,
"a 001 b"
and"a 1 b"
would be treated as equal, whilst
"a 1 b"
would be considered as occuring before "a 10 b"
,
which would not be the case with a simple lexicographic ordering.
s1
- the first of two strings to be compareds2
- the first of two strings to be comparedpublic static final boolean contains(java.lang.String string, java.lang.String[] substrings)
Does a string contain any one of an array of strings ?
string
- the string to testsubstrings
- an array of strings to look for within stringpublic static final boolean containsRegardlessOfCase(java.lang.String string, java.lang.String[] substrings)
Does a string contain any one of an array of strings regardless of case ?
string
- the string to testsubstrings
- an array of strings to look for within stringpublic static java.lang.String dump(char[] chars)
Create a dump of the decimal offset, hexadecimal values and printable string values of an array of char.
chars
- the array of char to be dumpedpublic static java.lang.String dump(java.lang.String s)
Create a dump of the decimal offset, hexadecimal values and printable string values of a String.
s
- the String to be dumped as if it were an array of charpublic static final java.util.Vector getDelimitedValues(java.lang.String string, java.lang.String delimiter)
Get delimited values from a string.
Consecutive delimiters result in an empty (zero length not null) string value.
Hence always returns a Vector one longer than the number of delimiters present.
string
- the string containing the delimited valuesdelimiter
- the delimiterpublic static java.lang.String getStringNoLongerThanTruncatedIfNecessary(java.lang.String str, int wanted)
public static java.lang.String padPositiveInteger(java.lang.String str, int length, java.lang.Character pad)
public static final java.lang.String removeLeadingCharacter(java.lang.String src, char rmchar)
Remove any leading instances of a particular character from a string.
src
- the string that may have leading charactersrmchar
- the character, all leading instances of which are to be removedpublic static final java.lang.String removeLeadingOrTrailingWhitespaceOrISOControl(java.lang.String src)
Remove any leading or trailing padding from a string.
Padding in this context means leading or trailing white space of any kind or null characters.
src
- the string that may have paddingpublic static final java.lang.String removeLeadingSpaces(java.lang.String src)
Remove any leading spaces from a string.
src
- the string that may have leading spacespublic static final java.lang.String removeLeadingWhitespaceOrISOControl(java.lang.String src)
Remove any leading instances of whitespace or control characters from a string.
src
- the string that may have trailing characterspublic static final java.lang.String removeTrailingCharacter(java.lang.String src, char rmchar)
Remove any trailing instances of a particular character from a string.
src
- the string that may have trailing charactersrmchar
- the character, all trailing instances of which are to be removedpublic static final java.lang.String removeTrailingSpaces(java.lang.String src)
Remove any trailing spaces from a string.
src
- the string that may have trailing spacespublic static final java.lang.String removeTrailingWhitespaceOrISOControl(java.lang.String src)
Remove any trailing instances of whitespace or control characters from a string.
src
- the string that may have trailing characterspublic static final java.lang.String replaceAllInWith(java.lang.String string, java.lang.String oldChars, java.lang.String newChars)
Replace all listed characters in a string with those listed as replacements.
If newchars is null or shorter than oldchars, the character will be deleted.
string
- the String to replace characters withinoldChars
- a String containing characters to be replacednewChars
- a String containing corresponding characters to use as replacements (may be null)public static java.lang.String toString(double[] doubleArray)
public static java.lang.String toString(java.lang.String[] stringArray)
public static java.lang.String toString(java.lang.String[][] stringArrays)
public static final java.lang.String toUpperCamelCase(java.lang.String string)
public static java.lang.String zeroPadPositiveInteger(java.lang.String str, int length)