allensoft.util
Class StringUtilities

java.lang.Object
  |
  +--allensoft.util.StringUtilities

public class StringUtilities
extends java.lang.Object

A miscelaneous collection of useful string utility functions.


Constructor Summary
StringUtilities()
           
 
Method Summary
static boolean containsWhiteSpace(java.lang.String s)
           
static java.lang.String expandTabs(java.lang.String sString, int nTabSize)
          Expands the the suplied string and returns a new string where tabs have been expanded to spaces.
static boolean matchesPattern(java.lang.String sString, java.lang.String sPattern)
          Determines if a string matches a pattern with case sensitivity.
static boolean matchesPattern(java.lang.String sString, java.lang.String sPattern, boolean bCaseSensitive)
          Determines if a string matches a pattern with or without case sensitivity.
static java.lang.String padZeros(int length, int value)
          Creates a string from an integer value and pads it with zeros at the start to fill the supplied length.
static java.lang.String padZeros(int length, int value, int base)
          Creates a string from an integer value using the specified base and pads it with zeros at the start to fill the supplied length.
static java.lang.String[] separateString(java.lang.String string)
          Seapartes the string using a comma without trimming of the separted strings.
static java.lang.String[] separateString(java.lang.String string, boolean trim)
          Seapartes the string using a comma with optional trimming of the separted strings.
static java.lang.String[] separateString(java.lang.String string, java.lang.String separator)
          Separates the string using the supplied separator without trimming the separted strings.
static java.lang.String[] separateString(java.lang.String string, java.lang.String separator, boolean trim)
          Separates the supplied string into separate strings which are separated by the separator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtilities

public StringUtilities()
Method Detail

padZeros

public static java.lang.String padZeros(int length,
                                        int value,
                                        int base)
Creates a string from an integer value using the specified base and pads it with zeros at the start to fill the supplied length. eg padZeros (5, 1, 10) returns "00001". If the value is negative then the minus sign is included in the length. eg padZeros (5, -1, 10) returns "-0001".
Parameters:
length - the length of the returned string after padding with zeros
value - the value to be padded with zeros.
base - the base to use for the number when represented as a string.

padZeros

public static java.lang.String padZeros(int length,
                                        int value)
Creates a string from an integer value and pads it with zeros at the start to fill the supplied length. eg padZeros (5, 1) returns "00001". If the value is negative then the minus sign is included in the length. eg padZeros (5, -1) returns "-0001". The base used for the returned string is base 10.
Parameters:
length - the length of the returned string after padding with zeros
value - the value to be padded with zeros.

separateString

public static java.lang.String[] separateString(java.lang.String string,
                                                java.lang.String separator,
                                                boolean trim)
Separates the supplied string into separate strings which are separated by the separator. The separated strings can be automatically trimmed (remove white space from start and end. eg separateString (" 1 , 2, 3, 4", ",", true) returns {"1","2","3","4"}.
Parameters:
string - the string to be separated
separator - the string used as the separator (e.g. ",")
trim - true if white space should be trimmed from the separated strings or false if they shouldn't

containsWhiteSpace

public static boolean containsWhiteSpace(java.lang.String s)

separateString

public static java.lang.String[] separateString(java.lang.String string,
                                                java.lang.String separator)
Separates the string using the supplied separator without trimming the separted strings.

separateString

public static java.lang.String[] separateString(java.lang.String string,
                                                boolean trim)
Seapartes the string using a comma with optional trimming of the separted strings.

separateString

public static java.lang.String[] separateString(java.lang.String string)
Seapartes the string using a comma without trimming of the separted strings.

matchesPattern

public static boolean matchesPattern(java.lang.String sString,
                                     java.lang.String sPattern,
                                     boolean bCaseSensitive)
Determines if a string matches a pattern with or without case sensitivity.
Parameters:
sString - The string to match against the pattern.
sPattern - The pattern to check against.
bCaseSensitive - true if case sensitivity should be used when matching the pattern or false otherwise.
Returns:
If the string matches the expression, true, else false.

matchesPattern

public static boolean matchesPattern(java.lang.String sString,
                                     java.lang.String sPattern)
Determines if a string matches a pattern with case sensitivity.
Parameters:
sString - The string to match against the pattern.
sPattern - The pattern to check against.
Returns:
If the string matches the expression, true, else false.

expandTabs

public static java.lang.String expandTabs(java.lang.String sString,
                                          int nTabSize)
Expands the the suplied string and returns a new string where tabs have been expanded to spaces.