Package com.pixelmed.utils

# Class StringUtilities

java.lang.Object
com.pixelmed.utils.StringUtilities

public class StringUtilities extends Object

Various static methods helpful for comparing and manipulating strings.

## Method Summary

Modifier and Type
Method
Description
`static final int`
`compareStringsThatMayBeIntegers(String s1, String s2)`
Compare strings based on their integer value of they are both integers, otherwise their lexicographic order.
`static final int`
`compareStringsWithEmbeddedNonZeroPaddedIntegers(String s1, String s2)`
Compare strings based on the lexicographic order of their values, but accounting for non-zero padded integers.
`static final boolean`
`contains(String string, String[] substrings)`
Does a string contain any one of an array of strings ?
`static final boolean`
`containsRegardlessOfCase(String string, String[] substrings)`
Does a string contain any one of an array of strings regardless of case ?
`static String`
`dump(char[] chars)`
Create a dump of the decimal offset, hexadecimal values and printable string values of an array of char.
`static String`
`dump(String s)`
Create a dump of the decimal offset, hexadecimal values and printable string values of a String.
`static final Vector`
`getDelimitedValues(String string, String delimiter)`
Get delimited values from a string.
`static String`
`getStringNoLongerThanTruncatedIfNecessary(String str, int wanted)`
`static String`
`padPositiveInteger(String str, int length, Character pad)`
`static final String`
`removeLeadingCharacter(String src, char rmchar)`
Remove any leading instances of a particular character from a string.
`static final String`
`removeLeadingOrTrailingWhitespaceOrISOControl(String src)`
Remove any leading or trailing padding from a string.
`static final String`
`removeLeadingSpaces(String src)`
Remove any leading spaces from a string.
`static final String`
`removeLeadingWhitespaceOrISOControl(String src)`
Remove any leading instances of whitespace or control characters from a string.
`static final String`
`removeTrailingCharacter(String src, char rmchar)`
Remove any trailing instances of a particular character from a string.
`static final String`
`removeTrailingSpaces(String src)`
Remove any trailing spaces from a string.
`static final String`
`removeTrailingWhitespaceOrISOControl(String src)`
Remove any trailing instances of whitespace or control characters from a string.
`static final String`
`replaceAllInWith(String string, String oldChars, String newChars)`
Replace all listed characters in a string with those listed as replacements.
`static String`
`toString(double[] doubleArray)`
`static String`
`toString(String[] stringArray)`
`static String`
`toString(String[][] stringArrays)`
`static final String`
`toUpperCamelCase(String string)`
`static String`
`zeroPadPositiveInteger(String str, int length)`

### Methods inherited from class java.lang.Object

`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### toUpperCamelCase

public static final String toUpperCamelCase(String string)

### replaceAllInWith

public static final String replaceAllInWith(String string, String oldChars, 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.

Parameters:
  `string` - the String to replace characters within
  `oldChars` - a String containing characters to be replaced
  `newChars` - a String containing corresponding characters to use as replacements (may be null)
Returns:
  a String with the characters replaced

### contains

public static final boolean contains(String string, String[] substrings)

Does a string contain any one of an array of strings ?

Parameters:
  `string` - the string to test
  `substrings` - an array of strings to look for within string
Returns:
  true if any string in substrings is found within string

### containsRegardlessOfCase

public static final boolean containsRegardlessOfCase(String string, String[] substrings)

Does a string contain any one of an array of strings regardless of case ?

Parameters:
  `string` - the string to test
  `substrings` - an array of strings to look for within string
Returns:
  true if any string in substrings is found within string

### getDelimitedValues

public static final Vector getDelimitedValues(String string, 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.

Parameters:
  `string` - the string containing the delimited values
  `delimiter` - the delimiter
Returns:
  a Vector of String values

### removeTrailingCharacter

public static final String removeTrailingCharacter(String src, char rmchar)

Remove any trailing instances of a particular character from a string.

Parameters:
  `src` - the string that may have trailing characters
  `rmchar` - the character, all trailing instances of which are to be removed
Returns:
  the value of the string argument with any instances of the trailing character removed

### removeTrailingWhitespaceOrISOControl

public static final String removeTrailingWhitespaceOrISOControl(String src)

Remove any trailing instances of whitespace or control characters from a string.

Parameters:
  `src` - the string that may have trailing characters
Returns:
  the value of the string argument with any instances of trailing whitespace or control characters removed

### removeLeadingCharacter

public static final String removeLeadingCharacter(String src, char rmchar)

Remove any leading instances of a particular character from a string.

Parameters:
  `src` - the string that may have leading characters
  `rmchar` - the character, all leading instances of which are to be removed
Returns:
  the value of the string argument with any instances of the leading character removed

### removeLeadingWhitespaceOrISOControl

public static final String removeLeadingWhitespaceOrISOControl(String src)

Remove any leading instances of whitespace or control characters from a string.

Parameters:
  `src` - the string that may have trailing characters
Returns:
  the value of the string argument with any instances of trailing whitespace or control characters removed

### removeTrailingSpaces

public static final String removeTrailingSpaces(String src)

Remove any trailing spaces from a string.

Parameters:
  `src` - the string that may have trailing spaces
Returns:
  the value of the string argument with any trailing spaces removed

### removeLeadingSpaces

public static final String removeLeadingSpaces(String src)

Remove any leading spaces from a string.

Parameters:
  `src` - the string that may have leading spaces
Returns:
  the value of the string argument with any leading spaces removed

### removeLeadingOrTrailingWhitespaceOrISOControl

public static final String removeLeadingOrTrailingWhitespaceOrISOControl(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.

Parameters:
  `src` - the string that may have padding
Returns:
  the value of the string argument with any padding removed

### compareStringsThatMayBeIntegers

public static final int compareStringsThatMayBeIntegers(String s1, 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.

Parameters:
  `s1` - the first of two strings to be compared
  `s2` - the first of two strings to be compared
Returns:
  the value 0 if the first string is equal to the second string; a value less than 0 if the first string is less than the second string; and a value greater than 0 if the first string is greater than the second string

### compareStringsWithEmbeddedNonZeroPaddedIntegers

public static final int compareStringsWithEmbeddedNonZeroPaddedIntegers(String s1, 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.

Parameters:
  `s1` - the first of two strings to be compared
  `s2` - the first of two strings to be compared
Returns:
  the value 0 if the first string is equal to the second string; a value less than 0 if the first string is lexicographically less than the second string; and a value greater than 0 if the first string is lexicographically greater than the second string

### dump

public static String dump(String s)

Create a dump of the decimal offset, hexadecimal values and printable string values of a String.

Parameters:
  `s` - the String to be dumped as if it were an array of char
Returns:
  a string containing the multiline result

### dump

public static String dump(char[] chars)

Create a dump of the decimal offset, hexadecimal values and printable string values of an array of char.

Parameters:
  `chars` - the array of char to be dumped
Returns:
  a string containing the multiline result

### toString

public static String toString(double[] doubleArray)

### toString

public static String toString(String[] stringArray)

### toString

public static String toString(String[][] stringArrays)

### padPositiveInteger

public static String padPositiveInteger(String str, int length, Character pad)

### zeroPadPositiveInteger

public static String zeroPadPositiveInteger(String str, int length)

### getStringNoLongerThanTruncatedIfNecessary

public static String getStringNoLongerThanTruncatedIfNecessary(String str, int wanted)