org.xnap.util
Class StringHelper

java.lang.Object
  extended by org.xnap.util.StringHelper

public class StringHelper
extends java.lang.Object

Provides a set of static methods that help with string parsing and modifying.


Field Summary
static java.lang.String ALPHA_NUM
           
static java.lang.String ALPHABET_LOWER
           
static java.lang.String ALPHABET_UPPER
           
static java.lang.String ANYTHING
           
static java.lang.String EMAIL
           
static java.lang.String HOST
           
static java.lang.String MONEY_USD
           
static java.lang.String NUMBERS_DECIMAL
           
static java.lang.String NUMBERS_INT
           
static java.lang.String REGULAR_STRING
           
 
Constructor Summary
StringHelper()
           
 
Method Summary
static java.lang.String firstToken(java.lang.String text, java.lang.String separator)
          Splits text at the first occurence of separator and returns the left part, excluding the separator.
static int indexOfDigit(java.lang.String s)
          Returns the index of the first digit in s.
static java.lang.String lastPrefix(java.lang.String text, java.lang.String separator)
          Splits text at the last occurence of separator and returns the left part, excluding the separator.
static java.lang.String lastToken(java.lang.String text, java.lang.String separator)
          Splits text at the last occurence of separator and returns the right part, excluding the separator.
static java.lang.String randomString(int length)
          Returns a random lower case letter-only string with length characters.
static java.lang.String replaceAll(java.lang.String s, java.lang.String oldChars, java.lang.String newChars)
          Replaces all occurences of oldChars in s by newChars.
static java.lang.String stripExtra(java.lang.String s)
          Removes all characters from s that are not letters.
static java.lang.String[] toArray(java.lang.String value, java.lang.String separators)
           
static java.lang.String toFirstUpper(java.lang.String value)
          Returns a new String that has the first letter of value set to upper case.
static int[] toIntArray(java.lang.String value, java.lang.String separators)
           
static java.util.LinkedList toList(java.lang.String value, java.lang.String separators)
           
static java.lang.String toString(byte[] data)
          Tries to autodect encoding.
static java.lang.String toString(java.util.Collection c, java.lang.String separator)
           
static java.lang.String toString(int[] array, java.lang.String separator)
           
static java.lang.String toString(java.lang.String[] array, java.lang.String separator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALPHABET_LOWER

public static final java.lang.String ALPHABET_LOWER
See Also:
Constant Field Values

ALPHABET_UPPER

public static final java.lang.String ALPHABET_UPPER
See Also:
Constant Field Values

NUMBERS_INT

public static final java.lang.String NUMBERS_INT
See Also:
Constant Field Values

NUMBERS_DECIMAL

public static final java.lang.String NUMBERS_DECIMAL
See Also:
Constant Field Values

MONEY_USD

public static final java.lang.String MONEY_USD
See Also:
Constant Field Values

ALPHA_NUM

public static final java.lang.String ALPHA_NUM
See Also:
Constant Field Values

EMAIL

public static final java.lang.String EMAIL
See Also:
Constant Field Values

HOST

public static final java.lang.String HOST
See Also:
Constant Field Values

REGULAR_STRING

public static final java.lang.String REGULAR_STRING
See Also:
Constant Field Values

ANYTHING

public static final java.lang.String ANYTHING
Constructor Detail

StringHelper

public StringHelper()
Method Detail

replaceAll

public static java.lang.String replaceAll(java.lang.String s,
                                          java.lang.String oldChars,
                                          java.lang.String newChars)
Replaces all occurences of oldChars in s by newChars.

Returns:
the modified instance of s

randomString

public static java.lang.String randomString(int length)
Returns a random lower case letter-only string with length characters.


toFirstUpper

public static java.lang.String toFirstUpper(java.lang.String value)
Returns a new String that has the first letter of value set to upper case.


stripExtra

public static java.lang.String stripExtra(java.lang.String s)
Removes all characters from s that are not letters. Returns a new String which can be for instance used as search text.

Returns:
a stripped instance of s

indexOfDigit

public static int indexOfDigit(java.lang.String s)
Returns the index of the first digit in s.

Returns:
-1, if s does not contain digits; the index of the first digit, otherwise
See Also:
String.indexOf(String)

firstToken

public static java.lang.String firstToken(java.lang.String text,
                                          java.lang.String separator)
Splits text at the first occurence of separator and returns the left part, excluding the separator.

Parameters:
text - the haystack
separator - the needle
Returns:
the empty string, if no occurence can be found

lastToken

public static java.lang.String lastToken(java.lang.String text,
                                         java.lang.String separator)
Splits text at the last occurence of separator and returns the right part, excluding the separator.

Parameters:
text - the haystack
separator - the needle
Returns:
the empty string, if no occurence can be found

lastPrefix

public static java.lang.String lastPrefix(java.lang.String text,
                                          java.lang.String separator)
Splits text at the last occurence of separator and returns the left part, excluding the separator.

Parameters:
text - the haystack
separator - the needle
Returns:
the empty string, if no occurence can be found

toArray

public static java.lang.String[] toArray(java.lang.String value,
                                         java.lang.String separators)

toIntArray

public static int[] toIntArray(java.lang.String value,
                               java.lang.String separators)

toList

public static java.util.LinkedList toList(java.lang.String value,
                                          java.lang.String separators)

toString

public static java.lang.String toString(byte[] data)
Tries to autodect encoding.


toString

public static java.lang.String toString(int[] array,
                                        java.lang.String separator)

toString

public static java.lang.String toString(java.lang.String[] array,
                                        java.lang.String separator)

toString

public static java.lang.String toString(java.util.Collection c,
                                        java.lang.String separator)


Copyright © 2001-2005 XNap Team. All Rights Reserved.