jodd.util
Class StringUtil

java.lang.Object
  extended byjodd.util.StringUtil

public final class StringUtil
extends java.lang.Object

General string utils.


Constructor Summary
StringUtil()
           
 
Method Summary
static boolean endsWithIgnoreCase(java.lang.String src, java.lang.String subS)
          Tests if this string ends with the specified suffix.
static boolean equals(java.lang.String s1, java.lang.String s2)
          Compares 2 strings.
static int indexOfIgnoreCase(java.lang.String src, java.lang.String subS)
          Finds first index of a substring in the given source string with ignored case.
static int indexOfIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)
          Finds first index of a substring in the given source string with ignored case.
static boolean isEmpty(java.lang.String s)
          Determines if a string is empty.
static int lastIndexOfIgnoreCase(java.lang.String s, java.lang.String subS)
          Finds last index of a substring in the given source string with ignored case.
static int lastIndexOfIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)
          Finds last index of a substring in the given source string with ignored case.
static java.lang.String replace(java.lang.String s, char sub, char with)
          Character replacement in a string.
static java.lang.String replace(java.lang.String s, java.lang.String sub, java.lang.String with)
          Replaces the occurences of a certain pattern in a string with a replacement String.
static java.lang.String setMaxLength(java.lang.String s, int len)
          Set the maximum length of the string.
static java.lang.String[] split(java.lang.String src, java.lang.String delimeter)
          Splits a string in several parts (tokens) that are separated by delimeter.
static java.lang.String[] splitc(java.lang.String src, java.lang.String d)
          Splits a string in several parts (tokens) that are separated by deliemter characters.
static boolean startsWithIgnoreCase(java.lang.String src, java.lang.String subS)
          Tests if this string starts with the specified prefix with ignored case.
static boolean startsWithIgnoreCase(java.lang.String src, java.lang.String subS, int startIndex)
          Tests if this string starts with the specified prefix with ignored case and with the specified prefix beginning a specified index.
static byte[] toByteArray(java.lang.String s)
          Converts string into byte array.
static java.lang.String toNotNullString(java.lang.Object obj)
          Converts an object to a String.
static java.lang.String toString(java.lang.Object obj)
          Converts an object to a String.
static java.lang.String[] toStringArray(java.lang.Object obj)
          Converts an object to a String Array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String sub,
                                       java.lang.String with)
Replaces the occurences of a certain pattern in a string with a replacement String. This is the fastest replace function.

Parameters:
s - the string to be inspected
sub - the string pattern to be replaced
with - the string that should go where the pattern was
Returns:
the string with the replacements done

replace

public static java.lang.String replace(java.lang.String s,
                                       char sub,
                                       char with)
Character replacement in a string. All occurrencies of a character will be replaces.

Parameters:
s - input string
sub - character to replace
with - character to replace with
Returns:
string with replaced characters

equals

public static boolean equals(java.lang.String s1,
                             java.lang.String s2)
Compares 2 strings. If one of the strings is null, false is returned. if both string are null, true is returned.

Parameters:
s1 - first string to compare
s2 - second string
Returns:
true if strings are equal, otherwise false

isEmpty

public static boolean isEmpty(java.lang.String s)
Determines if a string is empty. If string is NULL, it returns true.

Parameters:
s - string
Returns:
true if string is empty or null.

setMaxLength

public static java.lang.String setMaxLength(java.lang.String s,
                                            int len)
Set the maximum length of the string. If string is longer, it will be shorten.

Parameters:
s - string
len - max number of characters in string
Returns:
string with length no more then specified

toString

public static java.lang.String toString(java.lang.Object obj)
Converts an object to a String. If object is null it will be not converted.

Parameters:
obj - object to convert to string
Returns:
string created from the object or null

toNotNullString

public static java.lang.String toNotNullString(java.lang.Object obj)
Converts an object to a String. If object is null a empty string is returned.

Parameters:
obj - object to convert to string
Returns:
string created from the object

toStringArray

public static java.lang.String[] toStringArray(java.lang.Object obj)
Converts an object to a String Array.

Parameters:
obj - object to convert to string array
Returns:
string array created from the object

split

public static java.lang.String[] split(java.lang.String src,
                                       java.lang.String delimeter)
Splits a string in several parts (tokens) that are separated by delimeter. Delimeter is always surrounded by two strings! If there is no content between two delimeters, empty string will be returned for that token. Therefore, the length of the returned array will always be: #delimeters + 1.

Method is much, much faster then regexp String.split(), and a bit faster then StringTokenizer.

Parameters:
src - string to split
delimeter - split delimeter
Returns:
array of splitted strings

splitc

public static java.lang.String[] splitc(java.lang.String src,
                                        java.lang.String d)
Splits a string in several parts (tokens) that are separated by deliemter characters. Deliemter may contains any number of character, and it is always surrounded by two strings.

Parameters:
src - source to examine
d - string with delimeter characters
Returns:
array of tokens

toByteArray

public static byte[] toByteArray(java.lang.String s)
Converts string into byte array. Chars are truncated to byte size.

Parameters:
s - string to convert from
Returns:
byte array

indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String src,
                                    java.lang.String subS)
Finds first index of a substring in the given source string with ignored case.

Parameters:
src - source string for examination
subS - substring to find
Returns:
index of founded substring or -1 if substring is not found
See Also:
indexOfIgnoreCase(String, String, int)

indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String src,
                                    java.lang.String subS,
                                    int startIndex)
Finds first index of a substring in the given source string with ignored case. This seems to be the fastest way doing this, with common string length and content (of course, with no use of Boyer-Mayer type of algorithms). Other implementations are slower: getting char array frist, lowercasing the source string, using String.regionMatch etc.

Parameters:
src - source string for examination
subS - substring to find
startIndex - starting index from where search begins
Returns:
index of founded substring or -1 if substring is not found

lastIndexOfIgnoreCase

public static int lastIndexOfIgnoreCase(java.lang.String s,
                                        java.lang.String subS)
Finds last index of a substring in the given source string with ignored case.

Parameters:
s -
subS - substring to find
Returns:
last index of founded substring or -1 if substring is not found
See Also:
indexOfIgnoreCase(String, String, int), lastIndexOfIgnoreCase(String, String, int)

lastIndexOfIgnoreCase

public static int lastIndexOfIgnoreCase(java.lang.String src,
                                        java.lang.String subS,
                                        int startIndex)
Finds last index of a substring in the given source string with ignored case.

Parameters:
src - source string for examination
subS - substring to find
startIndex - starting index from where search begins
Returns:
last index of founded substring or -1 if substring is not found
See Also:
indexOfIgnoreCase(String, String, int)

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String src,
                                           java.lang.String subS)
Tests if this string starts with the specified prefix with ignored case.

Parameters:
src - source string to test
subS - starting substring
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise.

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String src,
                                           java.lang.String subS,
                                           int startIndex)
Tests if this string starts with the specified prefix with ignored case and with the specified prefix beginning a specified index.

Parameters:
src - source string to test
subS - starting substring
startIndex - index from where to test
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise.

endsWithIgnoreCase

public static boolean endsWithIgnoreCase(java.lang.String src,
                                         java.lang.String subS)
Tests if this string ends with the specified suffix.

Parameters:
src - String to test
subS - suffix
Returns:
true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise.


Jodd v0.24.5 Javadoc