org.jutil
Class TString

java.lang.Object
  extended by org.jutil.TString

public final class TString
extends java.lang.Object

This is the TString utility code class.

This code conforms to the code guides for org.jutil Utility Code

See Also:
org.jutiltest.TStringTest

Field Summary
static char[] ILLEGAL_NUMBER_CHARS
           
 
Constructor Summary
TString()
          Ensure that no one can create instances of this Class.
 
Method Summary
static java.lang.String capitalize(java.lang.String input)
          Capitalize the first letter of a word.
static java.lang.String getKey(java.lang.String str)
          getValue: get the key portion from a key/value java.lang.String pair
e.g "myKey=myValue" using the default delim char '=' as the divider
returns key portion of the java.lang.String
static java.lang.String getKey(java.lang.String str, char delim)
          get the key portion from a key/value String pair e.g "myKey=myValue"
using the delim char as the divider
returns key portion of the String
static java.lang.String getValue(java.lang.String str)
          getValue: get the value portion from a key/value java.lang.String
pair e.g "myKey=myValue" using the default delim char '=' as the divider
returns value portion of the java.lang.String
static java.lang.String getValue(java.lang.String str, char delim)
          getValue: get the value portion from a key/value java.lang.String
pair e.g "myKey=myValue" using the delim char as the divider
returns value portion of the java.lang.String
static int hash(java.lang.String str)
          returns an int hashed value of String str
static java.lang.String hexDecode(java.lang.String hex)
          Decode a hexadecimal String into its orgibnal form
static java.lang.String hexEncode(java.lang.String data)
          Code a String into a hexadecimal repsentation.
static boolean isEmpty(java.lang.String str)
          returns false is String is null or length < 1
static java.lang.String padLeft(java.lang.String str, int len, char pad)
          Pad the left hand side of a String str with the pad char to the len length
static java.lang.String padRight(java.lang.String str, int len, char pad)
          Pad the right hand side of a String str with the pad char to the len length
static java.lang.String proper(java.lang.String name)
          converts the first letter of a java.lang.String to uppercase
static java.lang.String removeChars(java.lang.String input, char[] remove)
           
static java.lang.String removeExcessSpace(java.lang.String input)
           
static java.lang.String removeExcessWhiteSpace(java.lang.String input)
           
static java.lang.String removeNewLine(java.lang.String input)
           
static java.lang.String removeTabs(java.lang.String input)
           
static java.lang.String replace(java.lang.String input, char flag, char replacement)
          replace all char flag in java.lang.String input
with char repacement
static java.lang.String replace(java.lang.String input, char flag, java.lang.String replacement)
          replace all char flag in java.lang.String input
with java.lang.String repacement
static java.lang.String replace(java.lang.String input, java.lang.String flag, char replacement)
          replace all java.lang.String flag in java.lang.String input
with char repacement
static java.lang.String replace(java.lang.String input, java.lang.String flag, java.lang.String replacement)
          replace all java.lang.String flag in java.lang.String input
with java.lang.String repacement
static java.lang.String snipLeft(java.lang.String str, int size)
          Pare the String str to the length size, by removing charcters on the left hand side
static java.lang.String snipRight(java.lang.String str, int size)
          Pare the String str to the length size, by removing charcters on the right hand side
static java.lang.String stripLeft(java.lang.String str, java.lang.String strip)
          Remove the strip String from the left hand side of the
str String str
static java.lang.String stripLeft(java.lang.String input, java.lang.String strip, int count)
          Remove the strip String from the left hand side of the String str recurse count times
Usage:org.jutil.TString.stripLeft("aabcd", "a", 1);
static java.lang.String stripRight(java.lang.String str, java.lang.String strip)
          Remove the strip String from the right hand side of the String str
static java.lang.String stripRight(java.lang.String input, java.lang.String strip, int count)
          Remove the strip String from the right hand side of the String str recurse count times
static java.lang.String[] toArray(java.lang.String str)
          converts a java.lang.String to a java.lang.String[] splitting
on the default ',' char
static java.lang.String[] toArray(java.lang.String input, char delim)
          toArray converts a java.lang.String to a java.lang.String[]
splitting on the delim char
static boolean tob(java.lang.String str)
          Convert String to boolean value
static boolean tob(java.lang.String str, boolean defaultValue)
          Convert String to boolean value
static java.lang.Boolean toBoolean(java.lang.String str)
          Convert String to Boolean value
static java.lang.Boolean toBoolean(java.lang.String str, boolean defaultValue)
          Convert String to Boolean value
static double tod(java.lang.String str)
          Convert String to double value:
static double tod(java.lang.String str, double defaultValue)
          Convert String to double value
static java.lang.Double toDouble(java.lang.String str)
          Convert String to Double value
static java.lang.Double toDouble(java.lang.String str, double defaultValue)
          Convert String to Double
static float tof(java.lang.String str)
          Convert String to float value:
static float tof(java.lang.String str, float defaultValue)
          Convert String to float value
static java.lang.Float toFloat(java.lang.String str)
          Convert String to Float value
static java.lang.Float toFloat(java.lang.String str, float defaultValue)
          Convert String to Float
static int toi(java.lang.String str)
          Convert String to int value
static int toi(java.lang.String str, int defaultValue)
          Convert String to int value
static java.lang.Integer toInteger(java.lang.String str)
          Convert String to Integer value
static java.lang.Integer toInteger(java.lang.String str, int defaultValue)
          Convert String to Integer
static long tol(java.lang.String str)
          Convert String to long value:
static long tol(java.lang.String str, long defaultValue)
          Convert String to long value
static java.lang.Long toLong(java.lang.String str)
          Convert String to Long value
static java.lang.Long toLong(java.lang.String str, long defaultValue)
          Convert String to Long
static java.lang.Object[] toObjectArray(java.lang.String str)
           
static java.lang.String[] wrap(java.lang.String source, int wrapAt)
          String[] desc = TString.wrap("12345678910123456789", 4);
lineSep == System.getProperty("line.separator")
static java.lang.String[] wrap(java.lang.String source, int wrapAt, java.lang.String lineSep)
          String[] desc = TString.wrap("12345678910123456789", 4, "\n");
lineSep can be null
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ILLEGAL_NUMBER_CHARS

public static final char[] ILLEGAL_NUMBER_CHARS
Constructor Detail

TString

public TString()
Ensure that no one can create instances of this Class.

Method Detail

capitalize

public static java.lang.String capitalize(java.lang.String input)
Capitalize the first letter of a word.

Usage:
org.jutil.TString.capitalize(String input);
        Stringbuffer result = new StringBuffer();
        StringTokenizer st = new StringTokenizer( "one two three" );
        while ( st.hasMoreTokens() ) {
                result.append( org.jutil.TString.capitalize( st.nextToken() ) );
        }
        System.out.println( "capitalize result==" + result.toString() );

Parameters:
input - java.lang.String
Returns:
capitalized java.lang.String

replace

public static final java.lang.String replace(java.lang.String input,
                                             java.lang.String flag,
                                             java.lang.String replacement)
replace all java.lang.String flag in java.lang.String input
with java.lang.String repacement

Usage:
org.jutil.TString.replace(String input, String flag, String replacement)

Parameters:
input - source java.lang.String
flag - java.lang.String to be replaced
replacement - java.lang.String to replace flag java.lang.String
Returns:
java.lang.String

replace

public static final java.lang.String replace(java.lang.String input,
                                             char flag,
                                             char replacement)
replace all char flag in java.lang.String input
with char repacement

Usage:
org.jutil.TString.replace(String input, char flag, char replacement)

Parameters:
input - source java.lang.String
flag - char to be replaced
replacement - char to replace flag char
Returns:
java.lang.String

removeChars

public static final java.lang.String removeChars(java.lang.String input,
                                                 char[] remove)

removeNewLine

public static final java.lang.String removeNewLine(java.lang.String input)

removeExcessSpace

public static final java.lang.String removeExcessSpace(java.lang.String input)

removeExcessWhiteSpace

public static final java.lang.String removeExcessWhiteSpace(java.lang.String input)

removeTabs

public static final java.lang.String removeTabs(java.lang.String input)

replace

public static final java.lang.String replace(java.lang.String input,
                                             char flag,
                                             java.lang.String replacement)
replace all char flag in java.lang.String input
with java.lang.String repacement

Usage:
org.jutil.TString.replace(String input, char flag, String replacement)

Parameters:
input - source java.lang.String
flag - char to be replaced
replacement - java.lang.String to replace flag char
Returns:
java.lang.String

replace

public static final java.lang.String replace(java.lang.String input,
                                             java.lang.String flag,
                                             char replacement)
replace all java.lang.String flag in java.lang.String input
with char repacement

Usage:
org.jutil.TString.replace(String input, String flag, char replacement)

Parameters:
input - source java.lang.String
flag - java.lang.String to be replaced
replacement - char to replace flag java.lang.String
Returns:
java.lang.String

proper

public static final java.lang.String proper(java.lang.String name)
converts the first letter of a java.lang.String to uppercase

Usage:
org.jutil.TString.proper(java.lang.String name)

Parameters:
input - name java.lang.String
Returns:
java.lang.String

toObjectArray

public static final java.lang.Object[] toObjectArray(java.lang.String str)

toArray

public static final java.lang.String[] toArray(java.lang.String str)
converts a java.lang.String to a java.lang.String[] splitting
on the default ',' char

Usage:
org.jutil.TString.toArray("item1,item2,item3");

Parameters:
str - java.lang.String
Returns:
java.lang.String[]

toArray

public static final java.lang.String[] toArray(java.lang.String input,
                                               char delim)
toArray converts a java.lang.String to a java.lang.String[]
splitting on the delim char

Usage:
org.jutil.TString.toArray("item1,item2,item3", ',');

Parameters:
str - java.lang.String
delim - char
Returns:
java.lang.String[]

getValue

public static final java.lang.String getValue(java.lang.String str)
getValue: get the value portion from a key/value java.lang.String
pair e.g "myKey=myValue" using the default delim char '=' as the divider
returns value portion of the java.lang.String

Usage:
org.jutil.TString.getValue(String str);


getValue

public static final java.lang.String getValue(java.lang.String str,
                                              char delim)
getValue: get the value portion from a key/value java.lang.String
pair e.g "myKey=myValue" using the delim char as the divider
returns value portion of the java.lang.String

Usage:
org.jutil.TString.getValue(String str, '=');


getKey

public static final java.lang.String getKey(java.lang.String str)
getValue: get the key portion from a key/value java.lang.String pair
e.g "myKey=myValue" using the default delim char '=' as the divider
returns key portion of the java.lang.String

Usage:
org.jutil.TString.getKey(String str);


getKey

public static final java.lang.String getKey(java.lang.String str,
                                            char delim)
get the key portion from a key/value String pair e.g "myKey=myValue"
using the delim char as the divider
returns key portion of the String

Usage:
org.jutil.TString.getKey(String str);


toi

public static final int toi(java.lang.String str)
Convert String to int value

Usage:
org.jutil.TString.toi(String str);

returns -1 if number format error occurs


toi

public static final int toi(java.lang.String str,
                            int defaultValue)
Convert String to int value

Usage:
org.jutil.TString.toi(String str);

returns defaultValue if number format error occurs


toInteger

public static final java.lang.Integer toInteger(java.lang.String str)
                                         throws java.lang.NumberFormatException
Convert String to Integer value

Usage:
org.jutil.TString.toInteger( final String str);

throws java.lang.NumberFormatException if number format error occurs

Throws:
java.lang.NumberFormatException

toInteger

public static final java.lang.Integer toInteger(java.lang.String str,
                                                int defaultValue)
Convert String to Integer

Usage:
org.jutil.TString.toInteger( final String str, int default);

returns defaultValue if number format error occurs or str is empty


tol

public static final long tol(java.lang.String str)
Convert String to long value:

Usage:
org.jutil.TString.tol( final String str);

returns -1l if number format error occurs


tol

public static final long tol(java.lang.String str,
                             long defaultValue)
Convert String to long value

Usage:
org.jutil.TString.tol( final String str, long default);

returns defaultValue if number format error occurs or str is empty


toLong

public static final java.lang.Long toLong(java.lang.String str)
                                   throws java.lang.NumberFormatException
Convert String to Long value

Usage:
org.jutil.TString.toLong( final String str);

throws java.lang.NumberFormatException if number format error occurs

Throws:
java.lang.NumberFormatException

toLong

public static final java.lang.Long toLong(java.lang.String str,
                                          long defaultValue)
Convert String to Long

Usage:
org.jutil.TString.toLong( final String str, long defaultValue);

returns defaultValue if number format error occurs or str is empty


tod

public static final double tod(java.lang.String str)
Convert String to double value:

Usage:
org.jutil.TString.tod( final String str);

returns -1d if number format error occurs


tod

public static final double tod(java.lang.String str,
                               double defaultValue)
Convert String to double value

Usage:
org.jutil.TString.tod( final String str, double default);

returns defaultValue if number format error occurs or str is empty


toDouble

public static final java.lang.Double toDouble(java.lang.String str)
                                       throws java.lang.NumberFormatException
Convert String to Double value

Usage:
org.jutil.TString.toDouble( final String str);

throws java.lang.NumberFormatException if number format error occurs

Throws:
java.lang.NumberFormatException

toDouble

public static final java.lang.Double toDouble(java.lang.String str,
                                              double defaultValue)
Convert String to Double

Usage:
org.jutil.TString.toDouble( final String str, double defaultValue);

returns defaultValue if number format error occurs or str is empty


tof

public static final float tof(java.lang.String str)
Convert String to float value:

Usage:
org.jutil.TString.tof( final String str);

returns -1.00f if number format error occurs


tof

public static final float tof(java.lang.String str,
                              float defaultValue)
Convert String to float value

Usage:
org.jutil.TString.tof( final String str, float defaultValue);

returns defaultValue if number format error occurs or str is empty


toFloat

public static final java.lang.Float toFloat(java.lang.String str)
                                     throws java.lang.NumberFormatException
Convert String to Float value

Usage:
org.jutil.TString.toFloat( final String str);

throws java.lang.NumberFormatException if number format error occurs

Throws:
java.lang.NumberFormatException

toFloat

public static final java.lang.Float toFloat(java.lang.String str,
                                            float defaultValue)
Convert String to Float

Usage:
org.jutil.TString.toFloat( final String str, float defaultValue);

returns defaultValue if number format error occurs or str is empty


tob

public static final boolean tob(java.lang.String str)
Convert String to boolean value

Usage:
org.jutil.TString.tob( final String str);

returns false if str is empty, if the str is not "true" or "false" (case irrelevent) returns false


tob

public static final boolean tob(java.lang.String str,
                                boolean defaultValue)
Convert String to boolean value

Usage:
org.jutil.TString.tob( final String str, true);

returns defaultValue if str is empty, if the str is not "true" or "false" (case irrelevent) returns false


toBoolean

public static final java.lang.Boolean toBoolean(java.lang.String str)
Convert String to Boolean value

Usage:
org.jutil.TString.toBoolean( final String str);


toBoolean

public static final java.lang.Boolean toBoolean(java.lang.String str,
                                                boolean defaultValue)
Convert String to Boolean value

Usage:
org.jutil.TString.toBoolean( final String str, true);

returns defaultValue if str is empty


snipLeft

public static final java.lang.String snipLeft(java.lang.String str,
                                              int size)
Pare the String str to the length size, by removing charcters on the left hand side

Usage:
org.jutil.TString.snipLeft("aabcd", 3);


result: "bcd"


snipRight

public static final java.lang.String snipRight(java.lang.String str,
                                               int size)
Pare the String str to the length size, by removing charcters on the right hand side

Usage:
org.jutil.TString.snipRight("aabcd", 3);


result: "aab"


stripLeft

public static final java.lang.String stripLeft(java.lang.String str,
                                               java.lang.String strip)
Remove the strip String from the left hand side of the
str String str

Usage:
org.jutil.TString.stripLeft("aabcd", "a");


result: "bcd"


stripLeft

public static final java.lang.String stripLeft(java.lang.String input,
                                               java.lang.String strip,
                                               int count)
Remove the strip String from the left hand side of the String str recurse count times
Usage:
org.jutil.TString.stripLeft("aabcd", "a", 1);


result: "abcd"

Usage:
org.jutil.TString.stripLeft("aabcd", "a", 2);
result: "bcd"


stripRight

public static final java.lang.String stripRight(java.lang.String str,
                                                java.lang.String strip)
Remove the strip String from the right hand side of the String str

Usage:
org.jutil.TString.stripRight("abcdd", "d");
result: "abc"


stripRight

public static final java.lang.String stripRight(java.lang.String input,
                                                java.lang.String strip,
                                                int count)
Remove the strip String from the right hand side of the String str recurse count times

Usage:
org.jutil.TString.stripRight("abcdd", "d", 1);
result: "abcd"

Usage:
org.jutil.TString.stripRight("abcdd", "d", 2);
result: "abc"


padLeft

public static final java.lang.String padLeft(java.lang.String str,
                                             int len,
                                             char pad)
Pad the left hand side of a String str with the pad char to the len length

Usage:
org.jutil.TString.padLeft("95", 10, '0');


result: "0000000095"


padRight

public static final java.lang.String padRight(java.lang.String str,
                                              int len,
                                              char pad)
Pad the right hand side of a String str with the pad char to the len length

Usage:
org.jutil.TString.padRight("95", 10, '0');


result: "9500000000"


hash

public static final int hash(java.lang.String str)
returns an int hashed value of String str

Usage:
org.jutil.TString.hash("123456");


isEmpty

public static final boolean isEmpty(java.lang.String str)
returns false is String is null or length < 1

Usage:
org.jutil.TString.isEmpty("123456");

white space is considered empty


wrap

public static final java.lang.String[] wrap(java.lang.String source,
                                            int wrapAt)
String[] desc = TString.wrap("12345678910123456789", 4);
lineSep == System.getProperty("line.separator")


wrap

public static final java.lang.String[] wrap(java.lang.String source,
                                            int wrapAt,
                                            java.lang.String lineSep)
String[] desc = TString.wrap("12345678910123456789", 4, "\n");
lineSep can be null


hexEncode

public static final java.lang.String hexEncode(java.lang.String data)
Code a String into a hexadecimal repsentation.

Usage:
org.jutil.TString.hexEncode("some data");

Parameters:
data - String to encode
Returns:
String for the specified encoding.

hexDecode

public static final java.lang.String hexDecode(java.lang.String hex)
Decode a hexadecimal String into its orgibnal form

Usage:
String str = org.jutil.TString.hexDecode("546869732069732061206C6F6E6720737472696E67");

Parameters:
hex - String to decode
Returns:
String