String

Description

Utility Functions to Operate on String and Char Properties

Functions

NameSignature and Synopsis
appendObject append(Object stringBuffer, String stringToAppend)
Appends strings to the buffer passed to it.
clearBuffervoid clearBuffer(Object stringBuffer)
Clears contents of the buffer passed to it.
compareToint compareTo (String s1, String s2)
Compares two strings lexicographically.
compareToIgnoreCaseint compareToIgnoreCase (String s1, String s2)
Compares two strings lexicographically, ignoring case differences.
concatString concat (String s1, String s2)
Concatenates the two argument strings and returns the resulting String.
containsboolean contains (String s1, String s2)
Tests if the String s1 contains the String s2.
convertBufferToStringString convertBufferToString(Object stringBuffer)
Appends strings to the buffer passed to it.
convertByteArrayToStringString convertByteArrayToString(Object bytesObject, String encoding)
A faster way of converting a {@link byte[]} to String object.

This is especially useful when the buffer sizes are very large, where {@link String#getBytes(String)} is not optimal.

createBufferObject createBuffer(int size)
Creates a new buffer to which strings can be appended instead of concat.
endsWithboolean endsWith (String s1, String suffix)
Tests if the String s1 ends with the specified suffix.
equalsboolean equals (String s1, String s2)
Compares two Strings and returns a boolean indicating whether they are equal.
formatString format(String message, Object... arguments)
Returns the message string formatted with arguments.
getBytesObject getBytes(String s1, String charsetName)
Encodes a string to a sequence of {@link byte[]} using the named charset.
hashCodeint hashCode (String s1)
Returns a hash code for the passed String.
indexOfStringint indexOfString (String s1, int fromIndex, String s2)
Returns the index within this string of the first occurrence of the specified substring.
lastIndexOfStringint lastIndexOfString (String s1, int fromIndex, String s2)
Returns the index within the String s1 of the last occurrence of the String s2.
leftString left (String s1, int length)
Returning a String containing the first length characters of the string s1.
lengthint length (String s1)
Returns the length of the String passed in.
matchesboolean matches (String s1, String regex)
Tells whether or not this string matches the given regular expression.
padString pad (String s1, int length, String padCharacter)
Returns a string padded to the indicated length with the pad character.
padFrontString padFront(String s1, int length, String padCharacter)
Returns a string front-padded to the indicated length with the pad character.
regionMatchesboolean regionMatches (boolean ignoreCase, String s1, int offset1, String s2, int offset2, int length)
Tests if two string regions are equal.
replaceAllString replaceAll (String s1, String regex, String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.
replaceFirstString replaceFirst (String s1, String regex, String replacement)
Replaces the first substring of this string that matches the given regular expression with the given replacement.
rightString right (String s1, int length)
Returning a String containing the last length characters of the string s1.
splitString[] split(String str, String regex)
Splits this string around matches of the given regular expression. Trailing empty strings are not included in the resulting array. e.g. String.split("This|is|a|test", "\\|") returns a String[] of {"This", "is", "a", "test"}.
split2String[] split2(String str, String regex, int limit)
Splits this string around matches of the given regular expression. The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit 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 . e.g. String.split2("This|is|a|test", "\\|",4) returns a String[] of {"This", "is", "a", "test"}. e.g. String.split2("##", "#") returns an empty String[] and String.split2("##", "#", -1) returns {"","",""}
startsWithboolean startsWith (String s1, String prefix)
Tests if the String s1 ends with the specified prefix.
substringString substring (String s1, int beginIndex, int endIndex)
Returns a new string that is a substring of this string.
substringAfterString substringAfter (String s1, String s2)
Return a String after the first occurence of the String s2 in String s1
substringBeforeString substringBefore (String s1, String s2)
Return a String before the first occurence of the String s2 in String s1
toLowerCaseString toLowerCase (String s1)
Converts all of the characters in the String passed to lower case using the rules of the default locale.
toUpperCaseString toUpperCase (String s1)
Converts all of the characters in the String passed to upper case using the rules of the default locale.
tokenizeString[] tokenize(String str, String delimiter)
Breaks an input string into tokens, returning tokens in a String[]. e.g. String.tokenize("This is a test", null) returns a String[] of {"This", "is", "a", "test"}.
trimString trim(String str)
Returns a copy of the string, with leading and trailing whitespace omitted.
valueOfBooleanString valueOfBoolean (boolean b)
Returns a String representation of the boolean passed in.
valueOfDoubleString valueOfDouble (double d)
Returns a String representation of the double passed in.
valueOfIntString valueOfInt (int i)
Returns a String representation of the int passed in.
valueOfLongString valueOfLong (long l)
Returns a String representation of the long passed in.