com.twelvemonkeys.lang
Class StringUtil

java.lang.Object
  extended by com.twelvemonkeys.lang.StringUtil

public final class StringUtil
extends Object

A utility class with some useful string manipulation methods.

Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/lang/StringUtil.java#2 $
Author:
Harald Kuhr, Eirik Torske, last modified by $Author: haku $

Field Summary
static String DELIMITER_STRING
          The default delimiter string, used by the toXXXArray() methods.
 
Method Summary
static String camelToLisp(String pString)
          Converts the input string from camel-style (Java in-fix) naming convention to Lisp-style naming convention (hyphen delimitted, all lower case).
static String capitalize(String pString)
          Makes the first letter of a String uppercase.
static String capitalize(String pString, int pIndex)
          Makes the Nth letter of a String uppercase.
static boolean contains(String pString, int pChar)
          Tests if a string contains a specific character.
static boolean contains(String pContainer, String pLookFor)
          Tests if a string contains another string.
static boolean containsIgnoreCase(String pString, int pChar)
          Tests if a string contains a specific character, ignoring case.
static boolean containsIgnoreCase(String pContainer, String pLookFor)
          Tests if a string contains another string, ignoring case.
static String cut(String pString, int pMaxLen, String pPad)
          Cuts a string between two words, before a sepcified length, if the string is longer than the maxium lenght.
static String decode(byte[] pData, int pOffset, int pLength, String pCharset)
          Constructs a new String by decoding the specified sub array of bytes using the specified charset.
static String deepToString(Object pObject)
           
static String deepToString(Object pObject, boolean pForceDeep, int pDepth)
           
static String getFirstElement(String pSource, String pDelimiter)
          Gets the first element of a String containing string elements delimited by a given delimiter.
static String getLastElement(String pSource, String pDelimiter)
          Gets the last element of a String containing string elements delimited by a given delimiter.
static String identityToString(Object pObject)
          Returns a string on the same format as Object.toString().
static int indexOfIgnoreCase(String pString, int pChar)
          Returns the index within this string of the first occurrence of the specified character.
static int indexOfIgnoreCase(String pString, int pChar, int pPos)
          Returns the index within this string of the first occurrence of the specified character, starting at the specified index.
static int indexOfIgnoreCase(String pString, String pLookFor)
          Returns the index within this string of the first occurrence of the specified substring.
static int indexOfIgnoreCase(String pString, String pLookFor, int pPos)
          Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
static boolean isEmpty(String pString)
          Tests if a String is null, or contains nothing but white-space.
static boolean isEmpty(String[] pStringArray)
          Tests a string array, to see if all items are null or an empty string.
static boolean isNumber(String pString)
          Tests a string, to see if it is an number (element of Z).
static int lastIndexOfIgnoreCase(String pString, int pChar)
          Returns the index within this string of the last occurrence of the specified character.
static int lastIndexOfIgnoreCase(String pString, int pChar, int pPos)
          Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.
static int lastIndexOfIgnoreCase(String pString, String pLookFor)
          Returns the index within this string of the rightmost occurrence of the specified substring.
static int lastIndexOfIgnoreCase(String pString, String pLookFor, int pPos)
          Returns the index within this string of the rightmost occurrence of the specified substring.
static String lispToCamel(String pString)
          Converts the input string from Lisp-style naming convention (hyphen delimitted, all lower case) to camel-style (Java in-fix) naming convention.
static String lispToCamel(String pString, boolean pFirstUpperCase)
          Converts the input string from Lisp-style naming convention (hyphen delimitted, all lower case) to camel-style (Java in-fix) naming convention.
static String ltrim(String pString)
          Trims the argument string for whitespace on the left side only.
 boolean matches(String pString, String pRegex)
          Tells whether or not the given string string matches the given regular expression.
static String pad(String pSource, int pRequiredLength, String pPadString, boolean pPrepend)
          String length check with simple concatenation of selected pad-string.
static String replace(String pSource, String pPattern, String pReplace)
          Replaces a substring of a string with another string.
 String replaceAll(String pString, String pRegex, String pReplacement)
          Replaces each substring of this string that matches the given regular expression with the given pReplacement.
 String replaceFirst(String pString, String pRegex, String pReplacement)
          Replaces the first substring of the given string that matches the given regular expression with the given pReplacement.
static String replaceIgnoreCase(String pSource, String pPattern, String pReplace)
          Replaces a substring of a string with another string, ignoring case.
static String reverse(String pString)
           
static String rtrim(String pString)
          Trims the argument string for whitespace on the right side only.
 String[] split(String pString, String pRegex)
          Splits this string around matches of the given regular expression.
 String[] split(String pString, String pRegex, int pLimit)
          Splits this string around matches of the given regular expression.
static String substring(String pSource, String pBeginBoundaryString, String pEndBoundaryString, int pOffset)
          Gets the first substring between the given string boundaries.
static Color toColor(String pString)
          Parses a string to a Color.
static String toColorString(Color pColor)
          Creates a HTML/CSS String representation of the given color.
static String toCSVString(Object[] pStringArray)
          Converts a string array to a string of comma-separated values.
static String toCSVString(Object[] pStringArray, String pDelimiterString)
          Converts a string array to a string separated by the given delimiter.
static Date toDate(String pString)
          Converts the string to a date, using the default date format.
static Date toDate(String pString, DateFormat pFormat)
          Converts the string to a date, using the given format.
static Date toDate(String pString, String pFormat)
          Converts the string to a date, using the given format.
static double[] toDoubleArray(String pString)
          Converts a comma-separated String to an array of doubles.
static double[] toDoubleArray(String pString, String pDelimiters)
          Converts a comma-separated String to an array of doubles.
static int[] toIntArray(String pString)
          Converts a comma-separated String to an array of ints.
static int[] toIntArray(String pString, String pDelimiters)
          Converts a comma-separated String to an array of ints.
static int[] toIntArray(String pString, String pDelimiters, int pBase)
          Converts a comma-separated String to an array of ints.
static long[] toLongArray(String pString)
          Converts a comma-separated String to an array of longs.
static long[] toLongArray(String pString, String pDelimiters)
          Converts a comma-separated String to an array of longs.
static String toLowerCase(String pString)
          Converts a string to lowercase.
static String[] toStringArray(String pString)
          Converts a comma-separated String to an array of Strings.
static String[] toStringArray(String pString, String pDelimiters)
          Converts a delimiter separated String to an array of Strings.
static Timestamp toTimestamp(String pValue)
          Converts the string to a jdbc Timestamp, using the standard Timestamp escape format.
static String toUpperCase(String pString)
          Converts a string to uppercase.
static String valueOf(Object pObj)
          Returns the value of the given Object, as a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DELIMITER_STRING

public static final String DELIMITER_STRING
The default delimiter string, used by the toXXXArray() methods. Its value is ", \t\n\r\f".

See Also:
toStringArray(String), toIntArray(String), toLongArray(String), toDoubleArray(String), Constant Field Values
Method Detail

decode

public static String decode(byte[] pData,
                            int pOffset,
                            int pLength,
                            String pCharset)
Constructs a new String by decoding the specified sub array of bytes using the specified charset. Replacement for new String(byte[], int, int, String), that does not throw the checked UnsupportedEncodingException, but instead the unchecked UnsupportedCharsetException if the character set is not supported.

Parameters:
pData - the bytes to be decoded to characters
pOffset - the index of the first byte to decode
pLength - the number of bytes to decode
pCharset - the name of a supported character set
Returns:
a newly created string.
Throws:
UnsupportedCharsetException
See Also:
String.String(byte[], int, int, String)

valueOf

public static String valueOf(Object pObj)
Returns the value of the given Object, as a String. Unlike String.valueOf, this method returns null instead of the String "null", if null is given as the argument.

Parameters:
pObj - the Object to find the String value of.
Returns:
the String value of the given object, or null if the pObj == null.
See Also:
String.valueOf(Object), String.toString()

toUpperCase

public static String toUpperCase(String pString)
Converts a string to uppercase.

Parameters:
pString - the string to convert
Returns:
the string converted to uppercase, or null if the argument was null.

toLowerCase

public static String toLowerCase(String pString)
Converts a string to lowercase.

Parameters:
pString - the string to convert
Returns:
the string converted to lowercase, or null if the argument was null.

isEmpty

public static boolean isEmpty(String pString)
Tests if a String is null, or contains nothing but white-space.

Parameters:
pString - The string to test
Returns:
true if the string is null or contains only whitespace, otherwise false.

isEmpty

public static boolean isEmpty(String[] pStringArray)
Tests a string array, to see if all items are null or an empty string.

Parameters:
pStringArray - The string array to check.
Returns:
true if the string array is null or only contains string items that are null or contain only whitespace, otherwise false.

contains

public static boolean contains(String pContainer,
                               String pLookFor)
Tests if a string contains another string.

Parameters:
pContainer - The string to test
pLookFor - The string to look for
Returns:
true if the container string is contains the string, and both parameters are non-null, otherwise false.

containsIgnoreCase

public static boolean containsIgnoreCase(String pContainer,
                                         String pLookFor)
Tests if a string contains another string, ignoring case.

Parameters:
pContainer - The string to test
pLookFor - The string to look for
Returns:
true if the container string is contains the string, and both parameters are non-null, otherwise false.
See Also:
contains(String,String)

contains

public static boolean contains(String pString,
                               int pChar)
Tests if a string contains a specific character.

Parameters:
pString - The string to check.
pChar - The character to search for.
Returns:
true if the string contains the specific character.

containsIgnoreCase

public static boolean containsIgnoreCase(String pString,
                                         int pChar)
Tests if a string contains a specific character, ignoring case.

Parameters:
pString - The string to check.
pChar - The character to search for.
Returns:
true if the string contains the specific character.

indexOfIgnoreCase

public static int indexOfIgnoreCase(String pString,
                                    String pLookFor)
Returns the index within this string of the first occurrence of the specified substring.

Parameters:
pString - The string to test
pLookFor - The string to look for
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
See Also:
String.indexOf(String)

indexOfIgnoreCase

public static int indexOfIgnoreCase(String pString,
                                    String pLookFor,
                                    int pPos)
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

Parameters:
pString - The string to test
pLookFor - The string to look for
pPos - The first index to test
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
See Also:
String.indexOf(String,int)

lastIndexOfIgnoreCase

public static int lastIndexOfIgnoreCase(String pString,
                                        String pLookFor)
Returns the index within this string of the rightmost occurrence of the specified substring. The rightmost empty string "" is considered to occur at the index value pString.length() - 1.

Parameters:
pString - The string to test
pLookFor - The string to look for
Returns:
If the string argument occurs one or more times as a substring within this object at a starting index no greater than fromIndex, then the index of the first character of the last such substring is returned. If it does not occur as a substring starting at fromIndex or earlier, -1 is returned.
See Also:
String.lastIndexOf(String)

lastIndexOfIgnoreCase

public static int lastIndexOfIgnoreCase(String pString,
                                        String pLookFor,
                                        int pPos)
Returns the index within this string of the rightmost occurrence of the specified substring. The rightmost empty string "" is considered to occur at the index value pPos

Parameters:
pString - The string to test
pLookFor - The string to look for
pPos - The last index to test
Returns:
If the string argument occurs one or more times as a substring within this object at a starting index no greater than fromIndex, then the index of the first character of the last such substring is returned. If it does not occur as a substring starting at fromIndex or earlier, -1 is returned.
See Also:
String.lastIndexOf(String,int)

indexOfIgnoreCase

public static int indexOfIgnoreCase(String pString,
                                    int pChar)
Returns the index within this string of the first occurrence of the specified character.

Parameters:
pString - The string to test
pChar - The character to look for
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
See Also:
String.indexOf(int)

indexOfIgnoreCase

public static int indexOfIgnoreCase(String pString,
                                    int pChar,
                                    int pPos)
Returns the index within this string of the first occurrence of the specified character, starting at the specified index.

Parameters:
pString - The string to test
pChar - The character to look for
pPos - The first index to test
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
See Also:
String.indexOf(int,int)

lastIndexOfIgnoreCase

public static int lastIndexOfIgnoreCase(String pString,
                                        int pChar)
Returns the index within this string of the last occurrence of the specified character.

Parameters:
pString - The string to test
pChar - The character to look for
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
See Also:
String.lastIndexOf(int)

lastIndexOfIgnoreCase

public static int lastIndexOfIgnoreCase(String pString,
                                        int pChar,
                                        int pPos)
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.

Parameters:
pString - The string to test
pChar - The character to look for
pPos - The last index to test
Returns:
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
See Also:
String.lastIndexOf(int,int)

ltrim

public static String ltrim(String pString)
Trims the argument string for whitespace on the left side only.

Parameters:
pString - the string to trim
Returns:
the string with no whitespace on the left, or null if the string argument is null.
See Also:
rtrim(java.lang.String), String.trim()

rtrim

public static String rtrim(String pString)
Trims the argument string for whitespace on the right side only.

Parameters:
pString - the string to trim
Returns:
the string with no whitespace on the right, or null if the string argument is null.
See Also:
ltrim(java.lang.String), String.trim()

replace

public static String replace(String pSource,
                             String pPattern,
                             String pReplace)
Replaces a substring of a string with another string. All matches are replaced.

Parameters:
pSource - The source String
pPattern - The pattern to replace
pReplace - The new String to be inserted instead of the replace String
Returns:
The new String with the pattern replaced

replaceIgnoreCase

public static String replaceIgnoreCase(String pSource,
                                       String pPattern,
                                       String pReplace)
Replaces a substring of a string with another string, ignoring case. All matches are replaced.

Parameters:
pSource - The source String
pPattern - The pattern to replace
pReplace - The new String to be inserted instead of the replace String
Returns:
The new String with the pattern replaced
See Also:
replace(String,String,String)

cut

public static String cut(String pString,
                         int pMaxLen,
                         String pPad)
Cuts a string between two words, before a sepcified length, if the string is longer than the maxium lenght. The string is optionally padded with the pad argument. The method assumes words to be separated by the space character (" "). Note that the maximum length argument is absolute, and will also include the length of the padding.

Parameters:
pString - The string to cut
pMaxLen - The maximum length before cutting
pPad - The string to append at the end, aftrer cutting
Returns:
The cutted string with padding, or the original string, if it was shorter than the max length.
See Also:
pad(String,int,String,boolean)

capitalize

public static String capitalize(String pString,
                                int pIndex)
Makes the Nth letter of a String uppercase. If the index is outside the the length of the argument string, the argument is simply returned.

Parameters:
pString - The string to capitalize
pIndex - The base-0 index of the char to capitalize.
Returns:
The capitalized string, or null, if a null argument was given.

capitalize

public static String capitalize(String pString)
Makes the first letter of a String uppercase.

Parameters:
pString - The string to capitalize
Returns:
The capitalized string, or null, if a null argument was given.

pad

public static String pad(String pSource,
                         int pRequiredLength,
                         String pPadString,
                         boolean pPrepend)
String length check with simple concatenation of selected pad-string. E.g. a zip number from 123 to the correct 0123.

Parameters:
pSource - The source string.
pRequiredLength - The accurate length of the resulting string.
pPadString - The string for concatenation.
pPrepend - The location of fill-ins, prepend (true), or append (false)
Returns:
a concatenated string.
See Also:
cut(String,int,String)

toDate

public static Date toDate(String pString)
Converts the string to a date, using the default date format.

Parameters:
pString - the string to convert
Returns:
the date
See Also:
DateFormat, DateFormat.getInstance()

toDate

public static Date toDate(String pString,
                          String pFormat)
Converts the string to a date, using the given format.

Parameters:
pString - the string to convert
pFormat - the date format
Returns:
the date
See Also:
SimpleDateFormat, SimpleDateFormat.SimpleDateFormat(String)

toDate

public static Date toDate(String pString,
                          DateFormat pFormat)
Converts the string to a date, using the given format.

Parameters:
pString - the string to convert
pFormat - the date format
Returns:
the date
See Also:
SimpleDateFormat, SimpleDateFormat.SimpleDateFormat(String), DateFormat

toTimestamp

public static Timestamp toTimestamp(String pValue)
Converts the string to a jdbc Timestamp, using the standard Timestamp escape format.

Parameters:
pValue - the value
Returns:
a new Timestamp
See Also:
Timestamp, Timestamp.valueOf(String)

toStringArray

public static String[] toStringArray(String pString,
                                     String pDelimiters)
Converts a delimiter separated String to an array of Strings.

Parameters:
pString - The comma-separated string
pDelimiters - The delimiter string
Returns:
a String array containing the delimiter separated elements

toStringArray

public static String[] toStringArray(String pString)
Converts a comma-separated String to an array of Strings.

Parameters:
pString - The comma-separated string
Returns:
a String array containing the comma-separated elements
See Also:
toStringArray(String,String)

toIntArray

public static int[] toIntArray(String pString,
                               String pDelimiters,
                               int pBase)
Converts a comma-separated String to an array of ints.

Parameters:
pString - The comma-separated string
pDelimiters - The delimiter string
pBase - The radix
Returns:
an int array
Throws:
NumberFormatException - if any of the elements are not parseable as an int

toIntArray

public static int[] toIntArray(String pString)
Converts a comma-separated String to an array of ints.

Parameters:
pString - The comma-separated string
Returns:
an int array
Throws:
NumberFormatException - if any of the elements are not parseable as an int
See Also:
toStringArray(String,String), DELIMITER_STRING

toIntArray

public static int[] toIntArray(String pString,
                               String pDelimiters)
Converts a comma-separated String to an array of ints.

Parameters:
pString - The comma-separated string
pDelimiters - The delimiter string
Returns:
an int array
Throws:
NumberFormatException - if any of the elements are not parseable as an int
See Also:
toIntArray(String,String)

toLongArray

public static long[] toLongArray(String pString,
                                 String pDelimiters)
Converts a comma-separated String to an array of longs.

Parameters:
pString - The comma-separated string
pDelimiters - The delimiter string
Returns:
a long array
Throws:
NumberFormatException - if any of the elements are not parseable as a long

toLongArray

public static long[] toLongArray(String pString)
Converts a comma-separated String to an array of longs.

Parameters:
pString - The comma-separated string
Returns:
a long array
Throws:
NumberFormatException - if any of the elements are not parseable as a long
See Also:
toStringArray(String,String), DELIMITER_STRING

toDoubleArray

public static double[] toDoubleArray(String pString,
                                     String pDelimiters)
Converts a comma-separated String to an array of doubles.

Parameters:
pString - The comma-separated string
pDelimiters - The delimiter string
Returns:
a double array
Throws:
NumberFormatException - if any of the elements are not parseable as a double

toDoubleArray

public static double[] toDoubleArray(String pString)
Converts a comma-separated String to an array of doubles.

Parameters:
pString - The comma-separated string
Returns:
a double array
Throws:
NumberFormatException - if any of the elements are not parseable as a double
See Also:
toDoubleArray(String,String), DELIMITER_STRING

toColor

public static Color toColor(String pString)
Parses a string to a Color. The argument can be a color constant (static constant from java.awt.Color), like black or red, or it can be HTML/CSS-style, on the format:

Parameters:
pString - the string representation of the color
Returns:
the Color object, or null if the argument is null
Throws:
IllegalArgumentException - if the string does not map to a color.
See Also:
Color

toColorString

public static String toColorString(Color pColor)
Creates a HTML/CSS String representation of the given color. The HTML/CSS color format is defined as:

Examlples: toColorString(Color.red) == "#ff0000", toColorString(new Color(0xcc, 0xcc, 0xcc)) == "#cccccc".

Parameters:
pColor - the color
Returns:
A String representation of the color on HTML/CSS form

isNumber

public static boolean isNumber(String pString)
Tests a string, to see if it is an number (element of Z). Valid integers are positive natural numbers (1, 2, 3, ...), their negatives (?1, ?2, ?3, ...) and the number zero.

Note that there is no guarantees made, that this number can be represented as either an int or a long.

Parameters:
pString - The string to check.
Returns:
true if the String is a natural number.

substring

public static String substring(String pSource,
                               String pBeginBoundaryString,
                               String pEndBoundaryString,
                               int pOffset)
Gets the first substring between the given string boundaries.

Parameters:
pSource - The source string.
pBeginBoundaryString - The string that marks the beginning.
pEndBoundaryString - The string that marks the end.
pOffset - The index to start searching in the source string. If it is less than 0, the index will be set to 0.
Returns:
the substring demarcated by the given string boundaries or null if not both string boundaries are found.

getFirstElement

public static String getFirstElement(String pSource,
                                     String pDelimiter)
Gets the first element of a String containing string elements delimited by a given delimiter. NB - Straightforward implementation!

Parameters:
pSource - The source string.
pDelimiter - The delimiter used in the source string.
Returns:
The last string element.

getLastElement

public static String getLastElement(String pSource,
                                    String pDelimiter)
Gets the last element of a String containing string elements delimited by a given delimiter. NB - Straightforward implementation!

Parameters:
pSource - The source string.
pDelimiter - The delimiter used in the source string.
Returns:
The last string element.

toCSVString

public static String toCSVString(Object[] pStringArray)
Converts a string array to a string of comma-separated values.

Parameters:
pStringArray - the string array
Returns:
A string of comma-separated values

toCSVString

public static String toCSVString(Object[] pStringArray,
                                 String pDelimiterString)
Converts a string array to a string separated by the given delimiter.

Parameters:
pStringArray - the string array
pDelimiterString - the delimiter string
Returns:
string of delimiter separated values
Throws:
IllegalArgumentException - if pDelimiterString == null

deepToString

public static String deepToString(Object pObject)
Parameters:
pObject - the object
Returns:
a deep string representation of the given object

deepToString

public static String deepToString(Object pObject,
                                  boolean pForceDeep,
                                  int pDepth)
Parameters:
pObject - the object
pDepth - the maximum depth
pForceDeep - true to force deep toString, even if object overrides toString
Returns:
a deep string representation of the given object

identityToString

public static String identityToString(Object pObject)
Returns a string on the same format as Object.toString().

Parameters:
pObject - the object
Returns:
the object as a String on the format of Object.toString()

matches

public boolean matches(String pString,
                       String pRegex)
                throws PatternSyntaxException
Tells whether or not the given string string matches the given regular expression.

An invocation of this method of the form matches(str, regex) yields exactly the same result as the expression

Pattern. matches (regex, str)

Parameters:
pString - the string
pRegex - the regular expression to which this string is to be matched
Returns:
true if, and only if, this string matches the given regular expression
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
See Also:
Pattern, String.matches(String)

replaceFirst

public String replaceFirst(String pString,
                           String pRegex,
                           String pReplacement)
Replaces the first substring of the given string that matches the given regular expression with the given pReplacement.

An invocation of this method of the form replaceFirst(str, regex, repl) yields exactly the same result as the expression

Pattern.compile(regex). matcher(str). replaceFirst(repl)

Parameters:
pString - the string
pRegex - the regular expression to which this string is to be matched
pReplacement - the replacement text
Returns:
The resulting String
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
See Also:
Pattern, Matcher.replaceFirst(String)

replaceAll

public String replaceAll(String pString,
                         String pRegex,
                         String pReplacement)
Replaces each substring of this string that matches the given regular expression with the given pReplacement.

An invocation of this method of the form replaceAll(str, pRegex, repl<) yields exactly the same result as the expression

Pattern.compile(pRegex). matcher(str). {@link java.util.regex.Matcher#replaceAll replaceAll}(repl)

Parameters:
pString - the string
pRegex - the regular expression to which this string is to be matched
pReplacement - the replacement string
Returns:
The resulting String
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
See Also:
Pattern, String.replaceAll(String,String)

split

public String[] split(String pString,
                      String pRegex,
                      int pLimit)
Splits this string around matches of the given regular expression.

The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.

The pLimit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the pLimit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

An invocation of this method of the form split(str, regex, n) yields the same result as the expression

Pattern. compile(regex). split(str, n)

Parameters:
pString - the string
pRegex - the delimiting regular expression
pLimit - the result threshold, as described above
Returns:
the array of strings computed by splitting this string around matches of the given regular expression
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
See Also:
Pattern, String.split(String,int)

split

public String[] split(String pString,
                      String pRegex)
Splits this string around matches of the given regular expression.

This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.

Parameters:
pString - the string
pRegex - the delimiting regular expression
Returns:
the array of strings computed by splitting this string around matches of the given regular expression
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
See Also:
Pattern, String.split(String)

camelToLisp

public static String camelToLisp(String pString)
Converts the input string from camel-style (Java in-fix) naming convention to Lisp-style naming convention (hyphen delimitted, all lower case). Other characters in the string are left untouched.

Eg. "foo" => "foo", "fooBar" => "foo-bar", "myURL" => "my-url", "HttpRequestWrapper" => "http-request-wrapper" "HttpURLConnection" => "http-url-connection" "my45Caliber" => "my-45-caliber" "allready-lisp" => "allready-lisp"

Parameters:
pString - the camel-style input string
Returns:
the string converted to lisp-style naming convention
Throws:
IllegalArgumentException - if pString == null
See Also:
lispToCamel(String)

lispToCamel

public static String lispToCamel(String pString)
Converts the input string from Lisp-style naming convention (hyphen delimitted, all lower case) to camel-style (Java in-fix) naming convention. Other characters in the string are left untouched.

Eg. "foo" => "foo", "foo-bar" => "fooBar", "http-request-wrapper" => "httpRequestWrapper" "my-45-caliber" => "my45Caliber" "allreadyCamel" => "allreadyCamel"

Parameters:
pString - the lisp-style input string
Returns:
the string converted to camel-style
Throws:
IllegalArgumentException - if pString == null
See Also:
lispToCamel(String,boolean), camelToLisp(String)

lispToCamel

public static String lispToCamel(String pString,
                                 boolean pFirstUpperCase)
Converts the input string from Lisp-style naming convention (hyphen delimitted, all lower case) to camel-style (Java in-fix) naming convention. Other characters in the string are left untouched.

To create a string starting with a lower case letter (like Java variable names, etc), specify the pFirstUpperCase paramter to be false. Eg. "foo" => "foo", "foo-bar" => "fooBar", "allreadyCamel" => "allreadyCamel"

To create a string starting with an upper case letter (like Java class name, etc), specify the pFirstUpperCase paramter to be true. Eg. "http-request-wrapper" => "HttpRequestWrapper" "my-45-caliber" => "My45Caliber"

Parameters:
pString - the lisp-style input string
pFirstUpperCase - true if the first char should be upper case
Returns:
the string converted to camel-style
Throws:
IllegalArgumentException - if pString == null
See Also:
camelToLisp(String)

reverse

public static String reverse(String pString)


Copyright © 2014. All Rights Reserved.