|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectariba.util.core.StringUtil
public final class StringUtil
String Utilities. These are utilities for working with strings.
| Nested Class Summary | |
|---|---|
static class |
StringUtil.SearchResult
Small struct class that captures the result of search for a string within some other unidentified string or stream. |
| Method Summary | |
|---|---|
static String |
bit(int pint)
Create the appropriate bit string for use in a LIKE clause for a string bit mask. |
static String |
bitClear(String value,
int pos)
Bit Clear - clear the bit with the given position in the given string Passing pos = 0 and value = "101" would yield "100". |
static String |
bitSet(String value,
int pos)
Bit Set - sets the bit with the given position in the given string Passing pos = 0 and value = "100" would yield "101". |
static boolean |
bitTest(String value,
int pos)
Bit Test - test the bit for the given position in the given string Passing pos = 0 and value = "100" would yield false Passing pos = 1 and value = "100" would yield false Passing pos = 2 and value = "100" would yield true |
static String |
capitalizeFirstChar(String string)
Returns string with the first character upper-cased. |
static boolean |
charsEqualString(char[] chars,
String s)
Compare a character array to a string without allocating a temporary string. |
static String |
compressSpaces(String s)
Replace all repeating instances of a space in a String with a single space. |
static boolean |
contains(String string,
String phrase)
Case insensitive string search for a substring. |
static String[] |
delimitedStringToArray(String str,
char delimiter)
Tokenize a String with a specified separator character and return an array. |
static boolean |
equalsIgnoreCase(String one,
String two)
Compares if two strings are equal or not. |
static String |
escapeRegEx(String regex)
Escapes metacharacters in a regex into literals. |
static String |
fastJoin(Collection collection,
String joinString)
Joins collection of elements with a string between each pair of elements. |
static String |
fastJoin(List vector,
String joinString)
Joins vector of elements with a string between each pair of elements. |
static byte[] |
getBytesUTF8(String string)
|
static String |
getStringUTF8(byte[] bytes)
|
static int |
indexOf(String string,
String[] substrings)
Search for any of an array of substrings inside of the specified string. |
static String |
intern(String source)
|
static boolean |
is7bitAscii(char c)
Specifies whether the given character is a 7-ascii character |
static boolean |
isAllDigits(String string)
Check if a String is composed entirely of digits using Character.isDigit |
static boolean |
isJavaIdentifier(String identifier)
Check if a string is a legal java identifier. |
static boolean |
isValidURIPart(String string,
boolean allowForExtendedMarks)
Specifies whether the given String is a valid URI part. |
static String |
join(List vector,
String joinString)
Joins vector of elements with a string between each pair of elements. |
static String |
join(Object[] objects,
String joinString)
Joins array of elements with a string between each pair of elements. |
static String |
join(Object[] objects,
String joinString,
int index,
int length)
Joins a sub-array of the given objects array elements
with a string between each pair of elements. |
static boolean |
nullOrEmptyOrBlankString(String string)
Determine if a string is null or empty or entirely spaces. |
static boolean |
nullOrEmptyString(String string)
Determine if a String is null or empty. |
static int |
occurs(String[] array,
String string)
Count the number of occurrences of a string in an array of Strings. |
static int |
occurs(String str,
char ch)
Count the number of occurrences of a character in a string. |
static int |
occurs(String str,
String substr)
Count the number of occurrences of a substring in a string. |
static String[] |
parseMatchingParentheses(String str)
|
static String |
printSecret(String value)
|
static String |
removeCarriageReturns(String string)
Removes the newlines and carriage returns from string
and returns the resultant string. |
static String[] |
removeDuplicates(String[] s)
To remove duplicate elements from a String array s |
static String[] |
removeDuplicates(String[] s,
StringArray duplicateArray)
To remove duplicate elements from a String array s |
static String |
removeLeadingSlashIfAny(String path)
Removes the leading slash from the given String. |
static String |
removeTrailingSlashIfAny(String path)
Removes the trailing slash from the given String. |
static String |
replaceCharByChar(String string,
char marker,
char replace)
Replace all occurrences of a character in a String with another character. |
static String |
replaceCharByString(String string,
char marker,
String replace)
Replace all occurrences of a character in a String with a String. |
static StringUtil.SearchResult |
search(String toSearch,
int fromIdx,
Collection toFind)
Searches for the first one of any of the supplied strings |
static String |
separateAtCapitalization(String string)
|
static String |
separateAtCapitalization(String string,
char separationChar)
|
static List |
splitWithQuotes(String str,
boolean keepQuotes)
Splits a string up into chunks using a whitespace delimiter. |
static boolean |
startsWithIgnoreCase(String string,
String other)
Check if a string starts with a specific substring in a case insensitive manner. |
static String |
strcat(String[] elems)
|
static String |
strcat(String s1,
String s2)
|
static String |
strcat(String s1,
String s2,
String s3)
|
static String |
strcat(String s1,
String s2,
String s3,
String s4)
|
static String |
strcat(String s1,
String s2,
String s3,
String s4,
String s5)
|
static String |
strcat(String s1,
String s2,
String s3,
String s4,
String s5,
String s6)
|
static String |
strcat(String s1,
String s2,
String s3,
String s4,
String s5,
String s6,
String s7)
|
static String |
strcat(String s1,
String s2,
String s3,
String s4,
String s5,
String s6,
String s7,
String s8)
|
static String |
strcat(String s1,
String s2,
String s3,
String s4,
String s5,
String s6,
String s7,
String s8,
String s9)
|
static int |
stringArrayIndex(String[] keys,
String key)
Performs a binary search on a sorted string array. |
static boolean |
stringMatchesPattern(String str,
String pattern)
Checks if a string matches a perl 5 pattern. |
static List |
stringToStringsListUsingBreakChars(String s,
String breakChars)
Tokenize a string separated by any separator characters into a List. |
static String |
substring(String string,
int beginIndex,
int endIndex)
Returns the substring of string from
beginIndex (inclusive) to endIndex,
exclusive. |
static String |
trailing(String string,
int length)
Returns the trailing part of string up to a max of
length characters. |
static String |
truncate(String string,
int length)
Returns this string truncated to a max of length
characters. |
static int |
unorderedStringArrayIndex(String[] keys,
String key)
Search an unsorted array of strings. |
static int |
unorderedStringArrayIndexIdentical(String[] keys,
String key)
Search an unsorted array of strings. |
static String |
wrap(String string,
String lineSeparator,
int wrapLength)
Return the string argument with the lineSeparator inserted every wrapLength- characters. |
static String |
wrapHTML(String string,
int wrapLength)
Return the string argument with " " tag inserted every wrapLength- characters. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean nullOrEmptyString(String string)
string - a String object to check
public static boolean nullOrEmptyOrBlankString(String string)
string - a String object to check
public static String capitalizeFirstChar(String string)
string with the first character upper-cased.
If string is already uppercased or if it is null
or less than one in length, the passed-in value is returned.
string with the first character upper-casedpublic static String separateAtCapitalization(String string)
public static String separateAtCapitalization(String string,
char separationChar)
public static final int stringArrayIndex(String[] keys,
String key)
keys - a sorted array of string keys to searchkey - a key to search for
public static String intern(String source)
public static boolean stringMatchesPattern(String str,
String pattern)
public static final int unorderedStringArrayIndexIdentical(String[] keys,
String key)
keys - an array of string keys to searchkey - a key to search for using the == operator
public static final int unorderedStringArrayIndex(String[] keys,
String key)
keys - an array of string keys to searchkey - a key to search for using the equals() method
public static String[] delimitedStringToArray(String str,
char delimiter)
Takes a string in the form "Description.Price.Amount" with a delimiter of '.' and turns it into an array of strings:
path[0] = "Description"
path[1] = "Price"
path[2] = "Amount"
str - a string to tokenizedelimiter - the delimiter to use when tokenizing
ListUtil.delimitedStringToList(java.lang.String, char)
public static int occurs(String str,
char ch)
str - the String to count inch - the character to count the occurrences of
public static int occurs(String str,
String substr)
str - the String to count insubstr - the substring to count the occurrences of
public static int occurs(String[] array,
String string)
array - an array of Strings to search in. There may not
be null elements in the array.string - the String to match against
public static boolean contains(String string,
String phrase)
string - the String to search inphrase - the String to search for
public static int indexOf(String string,
String[] substrings)
string - the String to search insubstrings - the strings to search for
-1 if the string is not found.
public static String replaceCharByChar(String string,
char marker,
char replace)
string - the string to do do the replacing on. If
null or empty string, the string is simply
returned.marker - the character to removereplace - the character to replace the removed character
marker with
public static String replaceCharByString(String string,
char marker,
String replace)
string - the string to do do the replacing on. If
null or empty string, the string is simply
returned.marker - the character to removereplace - the String that will replace the removed
marker. If an empty string or null is
passed, any occurrences of the marker are removed from
the initial string.
public static String compressSpaces(String s)
s - the string to be compressed
public static boolean charsEqualString(char[] chars,
String s)
chars - the characters to check against the Strings - the string to compare to the characters
public static List stringToStringsListUsingBreakChars(String s,
String breakChars)
s - the String to tokenizebreakChars - a string containing all characters to use as
separator characters for the tokenize
public static String substring(String string,
int beginIndex,
int endIndex)
string from
beginIndex (inclusive) to endIndex,
exclusive.
This function is "safe" in the sense that it will bound
beginIndex and endIndex appropriately so
that no exceptions will be thrown. E.g. if beginIndex is
less than zero, the zero index will be used for the substring instead.
string - the string to substringbeginIndex - the beginning index, inclusiveendIndex - the end index, exclusive
null if
string is null
public static String truncate(String string,
int length)
length
characters.
string - the string to truncatelength - the length of the truncated string
null if
string is null
public static String trailing(String string,
int length)
string up to a max of
length characters.
string - the string to get the trailing part oflength - the length of the truncated string
null if
string is null
public static String join(Object[] objects,
String joinString)
objects - an array of Objects each which will be toStringed.joinString - a string to separate each pair of elements, if
null the empty string is assumed
public static String join(Object[] objects,
String joinString,
int index,
int length)
throws IndexOutOfBoundsException
objects array elements
with a string between each pair of elements. The sub-array is
specified by the index offset and the
length.Range checking is delegated to the native access provided when accessing array elements.
objects - an array of Objects each which will be toStringed.joinString - a string to separate each pair of elements, if
null the empty string is assumedindex - the index within the array at which to begin the join of
the elements; should be >= 0 and
<= objects.length. (Note that if
index == objects.length, length must equal
0 in order that an exception will not be thrown.)length - the number of elements within the array to join
together; should satisfy
index + length <= objects.length
IndexOutOfBoundsException - if bounds specified lead to access
outside the bounds of the objects array
public static String fastJoin(List vector,
String joinString)
vector - a vector of Objects each which will be toStringed.joinString - a string to separate each pair of elements.
public static String fastJoin(Collection collection,
String joinString)
collection - a collection of Objects each which will be toStringed.joinString - a string to separate each pair of elements.
public static String join(List vector,
String joinString)
vector - a vector of Objects each which will be formatted
using the formatters.joinString - a string to separate each pair of elements.
public static boolean isJavaIdentifier(String identifier)
identifier - The string to check
public static boolean startsWithIgnoreCase(String string,
String other)
string - the string to search inother - the string to check for
String.startsWith(java.lang.String, int),
String.regionMatches(boolean, int, String, int, int)public static boolean isAllDigits(String string)
string - the String to check
Character.isDigit(char)
public static final String bitSet(String value,
int pos)
public static final String bitClear(String value,
int pos)
public static final boolean bitTest(String value,
int pos)
public static final String bit(int pint)
public static String strcat(String s1,
String s2)
public static String strcat(String s1,
String s2,
String s3)
public static String strcat(String s1,
String s2,
String s3,
String s4)
public static String strcat(String s1,
String s2,
String s3,
String s4,
String s5)
public static String strcat(String s1,
String s2,
String s3,
String s4,
String s5,
String s6)
public static String strcat(String s1,
String s2,
String s3,
String s4,
String s5,
String s6,
String s7)
public static String strcat(String s1,
String s2,
String s3,
String s4,
String s5,
String s6,
String s7,
String s8)
public static String strcat(String s1,
String s2,
String s3,
String s4,
String s5,
String s6,
String s7,
String s8,
String s9)
public static String strcat(String[] elems)
public static String[] removeDuplicates(String[] s)
s - a String array to unique
public static String removeCarriageReturns(String string)
string
and returns the resultant string.
string - the string to remove the carriage returns from
public static String[] removeDuplicates(String[] s,
StringArray duplicateArray)
s - a String array to uniqueduplicateArray - a list of duplicate array elements found
in String array s
public static String removeTrailingSlashIfAny(String path)
path - the given path String, must not be null.
public static String removeLeadingSlashIfAny(String path)
path - the given path String, must not be null.
public static String printSecret(String value)
public static boolean is7bitAscii(char c)
c - the character to test
true if the character c is a 7-ascii
character
public static boolean isValidURIPart(String string,
boolean allowForExtendedMarks)
true if all the characters part of the String follow the RFC
speficication.
However because some of these marks can be troublesome, this method will return false
if they are part of the String and allowForExtendedMarks is false.
string - the String to verify.allowForExtendedMarks - if false the marks '!', '~', '*', ''', '(' and ')'
will not be considered valid characters (although the RFC 2396 allows them.
true when the String complies with RFC 2396
public static List splitWithQuotes(String str,
boolean keepQuotes)
str - the string to splitkeepQuotes - if true keep the quotes that encapsulate an element
public static boolean equalsIgnoreCase(String one,
String two)
one - the String to be comparedtwo - the String to be compared
public static String wrapHTML(String string,
int wrapLength)
string - wrapLength -
public static String wrap(String string,
String lineSeparator,
int wrapLength)
StringUtil.wrap("Hello World!, null, 9) = Hello
World!
StringUtil.wrap("1234512345", "
", 5) = 1234512345
StringUtil.wrap("12345", 10) = 12345
string - The StringlineSeparator - Line break, "wrapLength - The position to create a line break
public static byte[] getBytesUTF8(String string)
public static String getStringUTF8(byte[] bytes)
public static String escapeRegEx(String regex)
public static StringUtil.SearchResult search(String toSearch,
int fromIdx,
Collection toFind)
toSearch - the string to searchfromIdx - the index at which to begin the search
public static String[] parseMatchingParentheses(String str)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||