|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ibm.commons.util.StringUtil
public class StringUtil
This class contains helpers for string manipulation.
Field Summary | |
---|---|
static java.lang.String |
EMPTY_STRING
|
static java.lang.String[] |
EMPTY_STRING_ARRAY
|
static java.lang.String |
SPACE
|
Constructor Summary | |
---|---|
StringUtil()
|
Method Summary | |
---|---|
static int |
compareTo(java.lang.String s1,
java.lang.String s2)
Compares two strings. |
static int |
compareToIgnoreCase(java.lang.String s1,
java.lang.String s2)
Compares two strings ignoring the case. |
static java.lang.String |
concatStrings(java.lang.String[] strings,
char sep,
boolean trim)
Concat a list of strings into a single string. |
static boolean |
contains(java.lang.Object[] objects,
java.lang.Object toTest)
|
static java.lang.String |
decrypt(java.lang.String pwd)
Deprecated. |
static java.lang.String |
encrypt(java.lang.String pwd)
Deprecated. |
static java.lang.String |
encrypt(java.lang.String pwd,
java.lang.String ctx)
Deprecated. |
static boolean |
endsWithIgnoreCase(java.lang.String s,
java.lang.String suffix)
Identical to String.endsWith but case insensitive. |
static boolean |
equals(java.lang.Object str1,
java.lang.Object str2)
Test if the specified objects are equal. |
static boolean |
equals(java.lang.String s1,
java.lang.String s2)
Test the string equality. |
static boolean |
equalsIgnoreCase(java.lang.String s1,
java.lang.String s2)
Test the string equality, ignoring the case. |
static java.lang.String |
expandProperties(java.lang.String s)
Property expander This function replaces all the occurences of ${propname} by the actual property value |
static java.lang.String |
format(java.lang.String fmt,
java.lang.Object... parameters)
Format a string. |
static java.lang.String |
fromXmlInputString(java.lang.String s)
Converts an HTML string to a Java one, converting the numeric entities (Ӓ) sent by the browser. |
static java.lang.String |
generateCopyName(java.lang.String sourceName,
java.lang.String[] listOfNames)
Create a name with the _copy_x appended, where X is the next available number. |
static java.lang.String |
getAutoGenNameFromJavaName(java.lang.String javaName)
|
static java.lang.String |
getDigest(java.lang.String str)
Transforms a String into a fixed-length digest. |
static java.lang.String[] |
getLineSeparators()
|
static char |
getMnemonicCharacter(java.lang.String text)
|
static java.lang.String |
getNextUniqueValue(java.lang.String name,
long startingNum,
java.lang.String[] listOfNames)
Given the current name, append a long until a unique is found, starting at the given starting num. |
static java.lang.String |
getNonNullString(java.lang.String string)
Return a non-null string if this string is null |
static java.lang.String |
getProperCaseString(java.lang.String sample)
Returns a string whose first letter is a Capital letter, and a space is inserted anywhere an upper case letter exists in the existing string. |
static char |
hexChar(int v)
|
static int |
hexValue(char c)
|
static int |
indexOfIgnoreCase(java.lang.String source,
java.lang.String str)
Returns the index within this string of the first occurrence of the specified string. |
static int |
indexOfIgnoreCase(java.lang.String source,
java.lang.String str,
int fromIndex)
Returns the index within this string of the first occurrence of the specified string. |
static boolean |
isContainedWithin(java.lang.String s,
java.lang.String[] container)
|
static boolean |
isEmpty(java.lang.String s)
Test if a string is empty. |
static boolean |
isEmpty(java.lang.String[] arr)
Checks if an array of string is empty. |
static boolean |
isEncrypted(java.lang.String pwd)
Deprecated. |
static boolean |
isFalseValue(java.lang.String stringToTest)
|
static boolean |
isLineSeparator(java.lang.String s)
|
static boolean |
isNotEmpty(java.lang.String s)
Test if a string is not empty. |
static boolean |
isNotEmpty(java.lang.String[] arr)
Checks if an array of string is not empty. |
static boolean |
isSpace(java.lang.String s)
Test if a string is only made of spaces. |
static boolean |
isTrueValue(java.lang.String stringToTest)
|
static int |
lastIndexOfIgnoreCase(java.lang.String source,
java.lang.String str)
Returns the index within this string of the last occurrence of the specified string. |
static int |
lastIndexOfIgnoreCase(java.lang.String source,
java.lang.String str,
int fromIndex)
Returns the index within this string of the last occurrence of the specified string. |
static java.lang.String |
ltrim(java.lang.String s)
Trims the space characters from the beginning of a string. |
static java.lang.String |
parseHtml(java.lang.String s)
Strip extra spaces and html tags. |
static java.lang.String |
removeLineBreaks(java.lang.String s)
Remove line breaks. |
static java.lang.String |
removeMnemonics(java.lang.String string)
Remove the mnemonics from a string. |
static java.lang.String |
removeMnemonics(java.lang.String string,
boolean remove)
A Helper function for conditionally calling removeMnemonics. |
static java.lang.String |
repeat(char toRepeat,
int count)
Create a new string by repeating a character. |
static java.lang.String |
repeat(java.lang.String toRepeat,
int count)
Create a new string by repeating a string. |
static java.lang.String |
replace(java.lang.String string,
char value,
char replace)
Replace all the occurrences of a character within a source string. |
static java.lang.String |
replace(java.lang.String source,
java.lang.String value,
java.lang.String replace)
Replace all the occurrences of a string within a source string. |
static java.lang.String |
replaceFirst(java.lang.String source,
java.lang.String value,
java.lang.String replace)
Replace the first occurrence of a string within a source string. |
static java.lang.String |
rtrim(java.lang.String s)
Trims the space characters from the end of a string. |
static java.lang.String[] |
splitString(java.lang.String s,
char sep)
Breaks a string into an array of substrings, with the delimeter removed. |
static java.lang.String[] |
splitString(java.lang.String s,
char sep,
boolean trim)
Breaks a string into an array of substrings, with the delimeter removed. |
static java.lang.String[] |
splitString(java.lang.String s,
java.lang.String sep,
boolean trim)
|
static boolean |
startsWithIgnoreCase(java.lang.String s,
java.lang.String prefix)
Identical to String.startsWith but case insensitive. |
static boolean |
startsWithIgnoreCase(java.lang.String s,
java.lang.String prefix,
int start)
Identical to String.startsWith but case insensitive. |
static java.lang.String |
toHexValue(byte[] barr)
Converts a byte array to a hexadecimal String equivalent. |
static java.lang.String |
toString(boolean value)
Convert a boolean to a string. |
static java.lang.String |
toString(byte value)
Convert a byte to a string. |
static java.lang.String |
toString(char ch)
Convert a character to a string. |
static java.lang.String |
toString(double value)
Convert a double to a string. |
static java.lang.String |
toString(float value)
Convert a float to a string. |
static java.lang.String |
toString(int value)
Convert an integer to a string. |
static java.lang.String |
toString(int value,
int digits,
char fill)
Convert a integer to its string representation and fill with characters on left to match the number of digits required. |
static java.lang.String |
toString(long value)
Convert a long to a string. |
static java.lang.String |
toString(java.lang.Object o)
Convert an object to a string. |
static java.lang.String |
toString(java.lang.Object value,
int max)
Convert a object to its string representation. |
static java.lang.String |
toString(short value)
Convert a short to a string. |
static java.lang.String[] |
toStringArray(java.util.Collection strings)
Converts a collection full of Strings to a string array. |
static java.lang.String |
toStringArray(java.lang.Object value,
int used,
int max)
|
static java.lang.String |
toUnsignedHex(int value,
int nChars)
Convert an integer to an Hexa string and pad the result with '0' |
static java.lang.String |
trim(char[] array)
Trims the spaces characters from both ends of of the character array. |
static java.lang.String |
trim(java.lang.String s)
Trims the space characters from both ends of a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static final java.lang.String SPACE
public static final java.lang.String EMPTY_STRING
Constructor Detail |
---|
public StringUtil()
Method Detail |
---|
public static final boolean equalsIgnoreCase(java.lang.String s1, java.lang.String s2)
s1
- the first string to compares2
- the first string to compare
public static java.lang.String concatStrings(java.lang.String[] strings, char sep, boolean trim)
strings
- the array of strings usedsep
- the separator between stringstrim
- indicate if the strings must be trimmed
public static final java.lang.String trim(java.lang.String s)
'\u0020'
(the space character) are considered to be
white space.
s
- the string to edit
public static final java.lang.String trim(char[] array)
array
- the char array to trim
public static int compareTo(java.lang.String s1, java.lang.String s2)
s1
- the first strings2
- the second string
0
if s1 is equal to s2. A value less than
0
if s1public static int compareToIgnoreCase(java.lang.String s1, java.lang.String s2)
s1
- the first strings2
- the second string
0
if s1 is equal to s2. A value less than
0
if s1public static final boolean equals(java.lang.String s1, java.lang.String s2)
s1
- the first string to compares2
- the first string to compare
public static boolean equals(java.lang.Object str1, java.lang.Object str2)
str1
- the first object to teststr2
- the second object to test
public static boolean isEmpty(java.lang.String s)
s
- the string to check
public static boolean isNotEmpty(java.lang.String s)
s
- the string to check
public static java.lang.String getNonNullString(java.lang.String string)
public static final boolean isSpace(java.lang.String s)
s
- the string to check
public static final java.lang.String format(java.lang.String fmt, java.lang.Object... parameters)
fmt
- the format stringp1
- the first message parameterp2
- the second message parameterp3
- the third message parameterp4
- the fourth message parameterp5
- the fifth message parameterp6
- the sixth message parameter
public static java.lang.String toString(java.lang.Object o)
o
- the object to convert
public static java.lang.String toString(char ch)
ch
- the character to convert
public static java.lang.String toString(byte value)
value
- the value to convert
public static java.lang.String toString(short value)
value
- the value to convert
public static java.lang.String toString(int value)
value
- the value to convert
public static java.lang.String toString(long value)
value
- the value to convert
public static java.lang.String toString(float value)
value
- the value to convert
public static java.lang.String toString(double value)
value
- the value to convert
public static java.lang.String toString(boolean value)
value
- the value to convert
public static final java.lang.String toString(java.lang.Object value, int max)
value
- the value to be converted
public static final java.lang.String toString(int value, int digits, char fill)
value
- the value to be converteddigits
- the number of desired digitsfill
- the character used to fill
public static java.lang.String[] toStringArray(java.util.Collection strings)
public static final java.lang.String toStringArray(java.lang.Object value, int used, int max)
public static final java.lang.String repeat(char toRepeat, int count)
toRepeat
- the character to repeatcount
- the number of repetition
public static final java.lang.String repeat(java.lang.String toRepeat, int count)
toRepeat
- the string to repeatcount
- the number of repetition
public static final java.lang.String replaceFirst(java.lang.String source, java.lang.String value, java.lang.String replace)
source
- the source stringvalue
- the string to search forreplace
- the string replacement
public static final java.lang.String replace(java.lang.String source, java.lang.String value, java.lang.String replace)
source
- the source stringvalue
- the string to search forreplace
- the string replacement
public static final java.lang.String replace(java.lang.String string, char value, char replace)
source
- the source stringvalue
- the character to search forreplace
- the character replacement
public static final java.lang.String toUnsignedHex(int value, int nChars)
value
- the int to convertnChars
- the number of characters of the result
java.lang.NumberFormatException
- if nChars is less that the actual number of characters neededpublic static final char hexChar(int v)
public static final int hexValue(char c)
public static java.lang.String[] splitString(java.lang.String s, char sep, boolean trim)
java.util.StringTokenizer
offers similar functionality.
This method differs by the fact that it returns all of the tokens at once,
using a String array, and does not require the explicit creation of a tokenizer
object. This function also returns empty strings when delimiters are concatened,
which is not the case of java.util.StringTokenizer
. Finally,
the delimiter is unique and passed as a char, which makes the method much faster.
s
- the string to splitc
- the delimetertrim
- indicates if the strings returned should be trimmed
public static java.lang.String[] splitString(java.lang.String s, java.lang.String sep, boolean trim)
public static final java.lang.String[] splitString(java.lang.String s, char sep)
java.util.StringTokenizer
offers similar functionality.
This method differs by the fact that it returns all of the tokens at once,
using a String array, and does not require the explicit creation of a tokenizer
object. This function also returns empty strings when delimiters are concatened,
which is not the case of java.util.StringTokenizer
. Finally,
the delimiter is unique and passed as a char, which makes the method much faster.
s
- the string to splitc
- the delimeter
public static final java.lang.String ltrim(java.lang.String s)
ltrim (" Tennessee")
returns the string "Tennessee".
s
- the string to edit
public static final java.lang.String rtrim(java.lang.String s)
rtrim ("Tennessee ")
returns the string "Tenness".'\u0020'
(the space character) are considered to be
white space.
s
- the string to edit
public static int indexOfIgnoreCase(java.lang.String source, java.lang.String str, int fromIndex)
source
- the string to searchstr
- the string to search forfromIndex
- the index to start from
-1
if the string does not occur.public static int indexOfIgnoreCase(java.lang.String source, java.lang.String str)
source
- the string to searchstr
- the string to search for
-1
if the string does not occur.public static int lastIndexOfIgnoreCase(java.lang.String source, java.lang.String str, int fromIndex)
source
- the string to searchstr
- the string to search forfromIndex
- the index to start from
-1
if the string does not occur.public static int lastIndexOfIgnoreCase(java.lang.String source, java.lang.String str)
source
- the string to searchstr
- the string to search for
-1
if the string does not occur.public static boolean startsWithIgnoreCase(java.lang.String s, java.lang.String prefix)
public static boolean startsWithIgnoreCase(java.lang.String s, java.lang.String prefix, int start)
public static boolean endsWithIgnoreCase(java.lang.String s, java.lang.String suffix)
public static boolean isEncrypted(java.lang.String pwd)
public static java.lang.String encrypt(java.lang.String pwd)
public static java.lang.String encrypt(java.lang.String pwd, java.lang.String ctx)
public static java.lang.String decrypt(java.lang.String pwd)
public static java.lang.String fromXmlInputString(java.lang.String s)
s
- the HTML string
public static boolean isTrueValue(java.lang.String stringToTest)
public static boolean isFalseValue(java.lang.String stringToTest)
public static java.lang.String getProperCaseString(java.lang.String sample)
sample:
- String - The string that you want to convert to proper case.
public static java.lang.String[] getLineSeparators()
public static java.lang.String removeLineBreaks(java.lang.String s)
public static java.lang.String parseHtml(java.lang.String s)
public static java.lang.String getAutoGenNameFromJavaName(java.lang.String javaName)
public static char getMnemonicCharacter(java.lang.String text)
public static java.lang.String generateCopyName(java.lang.String sourceName, java.lang.String[] listOfNames)
public static java.lang.String getNextUniqueValue(java.lang.String name, long startingNum, java.lang.String[] listOfNames)
public static java.lang.String removeMnemonics(java.lang.String string)
string
-
public static java.lang.String removeMnemonics(java.lang.String string, boolean remove)
string
- remove
- - if true remove any mnemonics in the string, if false just
return the string.
public static java.lang.String getDigest(java.lang.String str)
str
- the String to transform
public static java.lang.String toHexValue(byte[] barr)
public static boolean contains(java.lang.Object[] objects, java.lang.Object toTest)
public static boolean isLineSeparator(java.lang.String s)
public static boolean isEmpty(java.lang.String[] arr)
An array is empty if it is nul, or if it contains no elements.
arr
-
public static boolean isNotEmpty(java.lang.String[] arr)
An array is empty if it is nul, or if it contains no elements.
arr
-
public static boolean isContainedWithin(java.lang.String s, java.lang.String[] container)
public static java.lang.String expandProperties(java.lang.String s)
s
- flag
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |