org.dicom4j.core.utils
Class StringUtilities

java.lang.Object
  extended by org.dicom4j.core.utils.StringUtilities

public class StringUtilities
extends Object

Various static methods helpful for comparing and manipulating strings.

Author:
dclunie

Method Summary
static int compareStringsThatMayBeIntegers(String s1, String s2)
           Compare strings based on their integer value of they are both integers, otherwise their lexicographic order.
static int compareStringsWithEmbeddedNonZeroPaddedIntegers(String s1, String s2)
           Compare strings based on the lexicographic order of their values, but accounting for non-zero padded integers.
static void main(String[] arg)
           Unit testing.
static String removeTrailingCharacter(String src, char rmchar)
           Remove any trailing instances of a particular character from a string.
static String removeTrailingSpaces(String src)
           Remove any trailing spaces from a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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

main

public static void main(String[] arg)

Unit testing.

Parameters:
arg - ignored

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 spaces
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

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


Copyright © 2009 dicom4j. All Rights Reserved.