ViolinStrings
Class Strings

java.lang.Object
  extended byViolinStrings.Strings

public class Strings
extends Object

The Strings class provides a number of useful string manipulation methods. It cannot be instantiated.

You would typically use it in the following manner:

    String s = "abcdefg";
    String x = Strings.leftJustify(s, 20);
 

Some of the methods just call the equivalent methods from java.lang.String. They are provided to collect all string methods in one place.

Version:
1.01 2003/11/13
Author:
Michael Schmeling
See Also:
String, StringBuffer, Character

Constructor Summary
protected Strings()
           
 
Method Summary
static String center(String s, int len)
          Centers the string within a string of the specified length, padding it with blanks.
static String center(String s, int len, char pad)
          Centers the string within a string of the specified length, padding it with the specified character.
static String change(String s, char oldc, char newc)
          Changes occurrences of a specified character to a replacement character.
static String change(String s, char oldc, char newc, int start)
          Changes occurrences of a specified character to a replacement character.
static String change(String s, char oldc, char newc, int start, boolean ignoreCase)
          Changes occurrences of a specified character to a replacement character.
static String change(String s, char oldc, char newc, int start, int maxChanges)
          Changes occurrences of a specified character to a replacement character.
static String change(String s, char oldc, char newc, int start, int maxChanges, boolean ignoreCase)
          Changes occurrences of a specified character to a replacement character.
static String change(String s, String oldp, String newp)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, boolean ignoreCase)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, int start)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, int start, boolean ignoreCase)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, int start, int maxChanges)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, int start, int maxChanges, boolean ignoreCase)
          Changes occurrences of a specified pattern to a replacement string.
static int compare(String s1, String s2)
          Compares two strings.
static boolean contains(String s, String search)
          Returns true if the specified search string is contained in the original string.
static boolean contains(String s, String search, boolean ignoreCase)
          Returns true if the specified search string is contained in the original string.
static String copies(String s, int nCopies)
          Returns a string consisting of the specified number of copies of the input string.
static boolean endsWith(String s, String suffix)
          Returns true if the string ends with the specified suffix.
static boolean endsWith(String s, String suffix, boolean ignoreCase)
          Returns true if the string ends with the specified suffix.
static boolean equals(char c1, char c2, boolean ignoreCase)
          Checks if two characters are equal.
static boolean equals(String s1, String s2, boolean ignoreCase)
          Checks if two strings are equal.
static int indexOf(String s, char c)
          Returns the index of the first ocurrence of the specified character.
static int indexOf(String s, char c, boolean ignoreCase)
          Returns the index of the first ocurrence of the specified character.
static int indexOf(String s, char c, int start)
          Returns the index of the first ocurrence of the specified character.
static int indexOf(String s, char c, int start, boolean ignoreCase)
          Returns the index of the first ocurrence of the specified character, starting at the specified position.
static int indexOf(String s, String c)
          Returns the index of the first ocurrence of the specified string.
static int indexOf(String s, String c, boolean ignoreCase)
          Returns the index of the first ocurrence of the specified string, starting at the beginning of the string.
static int indexOf(String s, String c, int start)
          Returns the index of the first ocurrence of the specified string.
static int indexOf(String s, String c, int start, boolean ignoreCase)
          Returns the index of the first ocurrence of the specified string.
static int indexOfAnyBut(String s, String c)
          Returns the index of the first character that is not contained in the specified set of characters.
static int indexOfAnyBut(String s, String c, boolean ignoreCase)
          Returns the index of the first character that is not contained in the specified set of characters.
static int indexOfAnyBut(String s, String c, int start)
          Returns the index of the first character that is not contained in the specified set of characters.
static int indexOfAnyBut(String s, String c, int start, boolean ignoreCase)
          Returns the index of the first character that is not contained in the specified set of characters.
static int indexOfAnyOf(String s, String c)
          Returns the index of the first character that is contained in the specified set of characters.
static int indexOfAnyOf(String s, String c, boolean ignoreCase)
          Returns the index of the first character that is contained in the specified set of characters.
static int indexOfAnyOf(String s, String c, int start)
          Returns the index of the first character that is contained in the specified set of characters.
static int indexOfAnyOf(String s, String c, int start, boolean ignoreCase)
          Returns the index of the first character that is contained in the specified set of characters.
static int indexOfPhrase(String s, String p, int startWord)
          Returns the index of the first occurrence of the specified phrase within the string.
static int indexOfPhrase(String s, String p, int startWord, boolean ignoreCase)
          Returns the index of the first occurrence of the specified phrase within the string.
static int indexOfWord(String s, int wordNum)
          Returns the index of the first character of the specified nth word within the string.
static String insert(String s, String ins, int start)
          Inserts a string after the specified position.
static String insert(String s, String ins, int start, char pad)
          Inserts a string after the specified position.
static boolean isAbbreviationOf(String s, String full, boolean ignoreCase)
          Returns true if the string is a valid abbreviation of another string.
static boolean isAbbreviationOf(String s, String full, int minLength)
          Returns true if the string is a valid abbreviation of another string.
static boolean isAbbreviationOf(String s, String full, int minLength, boolean ignoreCase)
          Returns true if the string is a valid abbreviation of another string.
static boolean isDigit(String s)
          Returns true if the string consists of digits.
static boolean isIdentifierIgnorable(String s)
          Returns true if the string consists of ignorable characters in a Java identifier or a Unicode identifier.
static boolean isISOControl(String s)
          Returns true if the string consists of ISO control characters.
static boolean isJavaIdentifier(String s)
          Returns true if the string is a valid Java identifier.
static boolean isLetter(String s)
          Returns true if the string consists of letters.
static boolean isLetterOrDigit(String s)
          Returns true if the string consists of letters or digits.
static boolean isLike(String s, String pattern)
          Returns true if the string matches the specified pattern.
static boolean isLike(String s, String pattern, int start)
          Returns true if the string matches the specified pattern.
static boolean isLike(String s, String pattern, int start, boolean ignoreCase)
          Returns true if the string matches the specified pattern.
static boolean isLike(String s, String pattern, int start, char wAnySeq, char wAnyChar, boolean ignoreCase)
          Returns true if the string matches the specified pattern.
static boolean isLowerCase(String s)
          Returns true if the string consists of lowercase characters.
static boolean isSpaceChar(String s)
          Returns true if the string consists of Unicode space characters.
static boolean isTitleCase(String s)
          Returns true if the string consists of title case characters.
static boolean isUnicodeIdentifier(String s)
          Returns true if the string is a valid Unicode identifier.
static boolean isUpperCase(String s)
          Returns true if the string consists of uppercase characters.
static boolean isWhitespace(String s)
          Returns true if the string consists of whitespace characters.
static int lastIndexOf(String s, char c)
          Returns the index of the last ocurrence of the specified character.
static int lastIndexOf(String s, char c, int start)
          Returns the index of the last ocurrence of the specified character.
static int lastIndexOf(String s, char c, int start, boolean ignoreCase)
          Returns the index of the last ocurrence of the specified character.
static int lastIndexOf(String s, String c)
          Returns the index of the last ocurrence of the specified string.
static int lastIndexOf(String s, String c, boolean ignoreCase)
          Returns the index of the last ocurrence of the specified string.
static int lastIndexOf(String s, String c, int start)
          Returns the index of the last ocurrence of the specified string.
static int lastIndexOf(String s, String c, int start, boolean ignoreCase)
          Returns the index of the last ocurrence of the specified string.
static int lastIndexOfAnyBut(String s, String c)
          Returns the index of the last character that is not contained in the specified set of characters.
static int lastIndexOfAnyBut(String s, String c, int start)
          Returns the index of the last character that is not contained in the specified set of characters.
static int lastIndexOfAnyBut(String s, String c, int start, boolean ignoreCase)
          Returns the index of the last character that is not contained in the specified set of characters.
static int lastIndexOfAnyOf(String s, String c)
          Returns the index of the last character that is contained in the specified set of characters.
static int lastIndexOfAnyOf(String s, String c, int start)
          Returns the index of the last character that is contained in the specified set of characters.
static int lastIndexOfAnyOf(String s, String c, int start, boolean ignoreCase)
          Returns the index of the last character that is contained in the specified set of characters.
static String leftJustify(String s, int len)
          Left-justifies the string in a string of the specified length.
static String leftJustify(String s, int len, char pad)
          Left-justifies the string in a string of the specified length.
static int numWords(String s)
          Returns the number of words in the string.
static int occurrencesOf(String s, String c)
          Returns the number of occurrences of the specified string.
static int occurrencesOf(String s, String c, boolean ignoreCase)
          Returns the number of occurrences of the specified string.
static int occurrencesOf(String s, String c, int start)
          Returns the number of occurrences of the specified string.
static int occurrencesOf(String s, String c, int start, boolean ignoreCase)
          Returns the number of occurrences of the specified string.
static String overlayWith(String s, String o, int start)
          Replaces part of the string with the specified string, starting at a specified position.
static String overlayWith(String s, String o, int start, char pad)
          Replaces part of the string with the specified string, starting at a specified position.
static String remove(String s, int start, int numChars)
          Removes the specified number of characters from the string, starting at the specified position.
static String removeWords(String s, int startWord, int numWords)
          Removes the specified number of words from the string, starting with the specified word number.
static String reverse(String s)
          Reverses the sequence of characters contained in the string.
static String rightJustify(String s, int len)
          Right-justifies the string in a string of the specified length.
static String rightJustify(String s, int len, char pad)
          Right-justifies the string in a string of the specified length.
static String[] split(String s)
          Return an array of the constituent words of a string.
static String[] split(String s, int limit)
          Return an array of (at most) the first limit constituent words of a string.
static boolean startsWith(String s, String prefix)
          Returns true if the string starts with the specified prefix.
static boolean startsWith(String s, String prefix, boolean ignoreCase)
          Returns true if the string starts with the specified prefix.
static boolean startsWith(String s, String prefix, int start)
          Returns true if the string starts with the specified prefix.
static boolean startsWith(String s, String prefix, int start, boolean ignoreCase)
          Returns true if the string starts with the specified prefix.
static String strip(String s, char c)
          Strips the specified character from both ends of the string.
static String strip(String s, char c, boolean ignoreCase)
          Strips the specified character from both ends of the string.
static String strip(String s, String c)
          Strips the specified characters from both ends of the string.
static String strip(String s, String c, boolean ignoreCase)
          Strips the specified characters from both ends of the string.
static String stripBlanks(String s)
          Strips white space characters from both ends of the string.
static String stripLeading(String s, char c)
          Strips the specified leading character.
static String stripLeading(String s, char c, boolean ignoreCase)
          Strips the specified leading character.
static String stripLeading(String s, String c)
          Strips the specified leading characters.
static String stripLeading(String s, String c, boolean ignoreCase)
          Strips the specified leading characters.
static String stripLeadingBlanks(String s)
          Strips leading white space characters.
static String stripTrailing(String s, char c)
          Strips the specified trailing character.
static String stripTrailing(String s, char c, boolean ignoreCase)
          Strips the specified trailing character.
static String stripTrailing(String s, String c)
          Strips the specified trailing characters.
static String stripTrailing(String s, String c, boolean ignoreCase)
          Strips the specified trailing characters.
static String stripTrailingBlanks(String s)
          Strips trailing white space characters.
static String substring(String s, int start)
          Returns a substring of the specified string, starting at a specified position, and extending to the end of the string.
static String substring(String s, int start, int len)
          Returns a substring of the specified string, starting at a specified position, with the specified length.
static String substring(String s, int start, int len, char pad)
          Returns a substring of the specified string, starting at a specified position, with the specified length.
static String subWords(String s, int startWord, int numWords)
          Returns a substring of the string which starts at a specified word and contains the specified number of words.
static boolean toBoolean(String s)
          Returns true if the string represents the word "true".
static byte toByte(String s)
          If the string represents a valid byte value, returns this value as a byte.
static byte toByte(String s, int radix)
          If the string represents a valid byte value, returns this value as a byte.
static double toDouble(String s)
          If the string represents a valid double number, returns this number as a double value.
static float toFloat(String s)
          If the string represents a valid float number, returns this number as a float value.
static int toInt(String s)
          If the string represents a valid integer number, returns this number as an int value.
static int toInt(String s, int radix)
          If the string represents a valid integer number, returns this number as an int value.
static long toLong(String s)
          If the string represents a valid long integer, returns this number as a long value.
static long toLong(String s, int radix)
          If the string represents a valid long integer, returns this number as a long value.
static String toLowerCase(String s)
          Converts the string to lower case.
static String toLowerCase(String s, Locale locale)
          Converts the string to lower case using the given Locale.
static short toShort(String s)
          If the string represents a valid short number, returns this number as a short value.
static short toShort(String s, int radix)
          If the string represents a valid short number, returns this number as a short value.
static String toTitleCase(String s)
          Converts the string to titlecase.
static String toUpperCase(String s)
          Converts the string to upper case.
static String toUpperCase(String s, Locale locale)
          Converts the string to upper case using the given Locale.
static String translate(String s, String setin, String setout)
          Converts all of the string's characters which are contained in the input set of characters to the corresponding character in the output set of characters.
static String translate(String s, String setin, String setout, boolean ignoreCase)
          Converts all of the string's characters which are contained in the input set of characters to the corresponding character in the output set of characters.
static String translate(String s, String setin, String setout, char pad)
          Converts all of the string's characters which are contained in the input set of characters to the corresponding character in the output set of characters.
static String translate(String s, String setin, String setout, char pad, boolean ignoreCase)
          Converts all of the string's characters which are contained in the input set of characters to the corresponding character in the output set of characters.
static String word(String s, int wordNum)
          Returns the nth word in the string.
static int wordIndexOfPhrase(String s, String p, int startWord)
          Returns the number of the first word of the first occurrence of the specified phrase within the string.
static int wordIndexOfPhrase(String s, String p, int startWord, boolean ignoreCase)
          Returns the number of the first word of the first occurrence of the specified phrase within the string.
static String wordSpace(String s, int spaces)
          All whitespace between the words of the string is replaced by the specified number of blanks.
static String xRange(char start, char end)
          Builds a string consisting of all characters between 'start' and 'end'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

protected Strings()
Method Detail

equals

public static boolean equals(char c1,
                             char c2,
                             boolean ignoreCase)
Checks if two characters are equal. You can specify that case should be ignored.

Parameters:
c1 - first character
c2 - second character
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the characters are equal, false otherwise
See Also:
string

equals

public static boolean equals(String s1,
                             String s2,
                             boolean ignoreCase)
Checks if two strings are equal. You can specify that case should be ignored.

Parameters:
s1 - first string
s2 - second string
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the strings are equal, false otherwise
See Also:
string

compare

public static int compare(String s1,
                          String s2)
Compares two strings.

Parameters:
s1 - the first string
s2 - second string
Returns:
0 if the two strings are equal, a value less than zero if s1 is lexicographically less than s2, and a value greater than zero if s1 is lexicographically greater than s2.
See Also:
string

startsWith

public static boolean startsWith(String s,
                                 String prefix,
                                 boolean ignoreCase)
Returns true if the string starts with the specified prefix.

Parameters:
s - the input string
prefix - the prefix
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the string starts with the specified prefix.
See Also:
string, string

startsWith

public static boolean startsWith(String s,
                                 String prefix)
Returns true if the string starts with the specified prefix.

Parameters:
s - the input string
prefix - the prefix
Returns:
true if the string starts with the specified prefix.
See Also:
string

startsWith

public static boolean startsWith(String s,
                                 String prefix,
                                 int start)
Returns true if the string starts with the specified prefix.

Parameters:
s - the input string
prefix - the prefix
start - the starting position for the test
Returns:
true if the string starts with the specified prefix.
See Also:
string

startsWith

public static boolean startsWith(String s,
                                 String prefix,
                                 int start,
                                 boolean ignoreCase)
Returns true if the string starts with the specified prefix.

Parameters:
s - the input string
prefix - the prefix
start - the starting position for the test
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the string starts with the specified prefix.
See Also:
string, string

endsWith

public static boolean endsWith(String s,
                               String suffix,
                               boolean ignoreCase)
Returns true if the string ends with the specified suffix.

Parameters:
s - the input string
suffix - the suffix
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the string ends with the specified suffix.
See Also:
string, string

endsWith

public static boolean endsWith(String s,
                               String suffix)
Returns true if the string ends with the specified suffix.

Parameters:
s - the input string
suffix - the suffix
Returns:
true if the string ends with the specified suffix.
See Also:
string

indexOf

public static int indexOf(String s,
                          String c,
                          int start)
Returns the index of the first ocurrence of the specified string.

Parameters:
s - the string to be inspected
c - the string to be searched for
start - the starting position for the search
Returns:
the index of the first ocurrence of the specified string. If the specified string is not found -1 is returned.
See Also:
string

indexOf

public static int indexOf(String s,
                          String c,
                          int start,
                          boolean ignoreCase)
Returns the index of the first ocurrence of the specified string. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the string to be searched for
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first ocurrence of the specified string. If the specified string is not found -1 is returned.
See Also:
string

indexOf

public static int indexOf(String s,
                          String c,
                          boolean ignoreCase)
Returns the index of the first ocurrence of the specified string, starting at the beginning of the string. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the string to be searched for
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first ocurrence of the specified string. If the specified string is not found -1 is returned.

indexOf

public static int indexOf(String s,
                          String c)
Returns the index of the first ocurrence of the specified string.

Parameters:
s - the string to be inspected
c - the string to be searched for
Returns:
the index of the first ocurrence of the specified string. If the specified string is not found -1 is returned.
See Also:
string

indexOf

public static int indexOf(String s,
                          char c)
Returns the index of the first ocurrence of the specified character.

Parameters:
s - the string to be inspected
c - the character to be searched for
Returns:
the index of the first ocurrence of the specified character. If the specified character is not found -1 is returned.
See Also:
string

indexOf

public static int indexOf(String s,
                          char c,
                          int start,
                          boolean ignoreCase)
Returns the index of the first ocurrence of the specified character, starting at the specified position. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the character to be searched for
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first ocurrence of the specified character. If the specified character is not found -1 is returned.
See Also:
string

indexOf

public static int indexOf(String s,
                          char c,
                          boolean ignoreCase)
Returns the index of the first ocurrence of the specified character. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the character to be searched for
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first ocurrence of the specified character. If the specified character is not found -1 is returned.

indexOf

public static int indexOf(String s,
                          char c,
                          int start)
Returns the index of the first ocurrence of the specified character.

Parameters:
s - the string to be inspected
c - the character to be searched for
start - the starting position for the search
Returns:
the index of the first ocurrence of the specified character. If the specified character is not found -1 is returned.
See Also:
string

indexOfAnyOf

public static int indexOfAnyOf(String s,
                               String c,
                               int start)
Returns the index of the first character that is contained in the specified set of characters.

Parameters:
s - the string to be inspected
c - the set of characters
start - the starting position for the search
Returns:
the index of the first character that is contained in the specified set of characters. If no character from the string is in the specified set of characters -1 is returned.

indexOfAnyOf

public static int indexOfAnyOf(String s,
                               String c,
                               int start,
                               boolean ignoreCase)
Returns the index of the first character that is contained in the specified set of characters. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the set of characters
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first character that is contained in the specified set of characters. If no character from the string is in the specified set of characters -1 is returned.

indexOfAnyOf

public static int indexOfAnyOf(String s,
                               String c,
                               boolean ignoreCase)
Returns the index of the first character that is contained in the specified set of characters. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the set of characters
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first character that is contained in the specified set of characters. If no character from the string is in the specified set of characters -1 is returned.

indexOfAnyOf

public static int indexOfAnyOf(String s,
                               String c)
Returns the index of the first character that is contained in the specified set of characters.

Parameters:
s - the string to be inspected
c - the set of characters
Returns:
the index of the first character that is contained in the specified set of characters. If no character from the string is in the specified set of characters -1 is returned.

indexOfAnyBut

public static int indexOfAnyBut(String s,
                                String c,
                                int start,
                                boolean ignoreCase)
Returns the index of the first character that is not contained in the specified set of characters. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the set of characters
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first character that is not contained in the specified set of characters. If no such character is found -1 is returned.

indexOfAnyBut

public static int indexOfAnyBut(String s,
                                String c,
                                boolean ignoreCase)
Returns the index of the first character that is not contained in the specified set of characters. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the set of characters
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first character that is not contained in the specified set of characters. If no such character is found -1 is returned.

indexOfAnyBut

public static int indexOfAnyBut(String s,
                                String c,
                                int start)
Returns the index of the first character that is not contained in the specified set of characters.

Parameters:
s - the string to be inspected
c - the set of characters
start - the starting position for the search
Returns:
the index of the first character that is not contained in the specified set of characters. If no such character is found -1 is returned.

indexOfAnyBut

public static int indexOfAnyBut(String s,
                                String c)
Returns the index of the first character that is not contained in the specified set of characters.

Parameters:
s - the string to be inspected
c - the set of characters
Returns:
the index of the first character that is not contained in the specified set of characters. If no such character is found -1 is returned.

occurrencesOf

public static int occurrencesOf(String s,
                                String c,
                                int start,
                                boolean ignoreCase)
Returns the number of occurrences of the specified string. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the string to search for
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the number of occurrences of the specified string. If the string is not found -1 is returned.

occurrencesOf

public static int occurrencesOf(String s,
                                String c,
                                boolean ignoreCase)
Returns the number of occurrences of the specified string. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the string to search for
ignoreCase - if true ignore case when comparing characters
Returns:
the number of occurrences of the specified string. If the string is not found -1 is returned.

occurrencesOf

public static int occurrencesOf(String s,
                                String c,
                                int start)
Returns the number of occurrences of the specified string.

Parameters:
s - the string to be inspected
c - the string to search for
start - the starting position for the search
Returns:
the number of occurrences of the specified string. If the string is not found -1 is returned.

occurrencesOf

public static int occurrencesOf(String s,
                                String c)
Returns the number of occurrences of the specified string.

Parameters:
s - the string to be inspected
c - the string to search for
Returns:
the number of occurrences of the specified string. If the string is not found -1 is returned.

lastIndexOf

public static int lastIndexOf(String s,
                              String c,
                              int start,
                              boolean ignoreCase)
Returns the index of the last ocurrence of the specified string. The search is performed backwards from the specified starting position. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the string to be searched for
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the last ocurrence of the specified string. If the specified string is not found -1 is returned.
See Also:
string

lastIndexOf

public static int lastIndexOf(String s,
                              String c,
                              boolean ignoreCase)
Returns the index of the last ocurrence of the specified string. The search is performed backwards from the end of the string. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the string to be searched for
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the last ocurrence of the specified string. If the specified string is not found -1 is returned.

lastIndexOf

public static int lastIndexOf(String s,
                              String c,
                              int start)
Returns the index of the last ocurrence of the specified string. The search is performed backwards from the specified starting position.

Parameters:
s - the string to be inspected
c - the string to be searched for
start - the starting position for the search
Returns:
the index of the last ocurrence of the specified string. If the specified string is not found -1 is returned.
See Also:
string

lastIndexOf

public static int lastIndexOf(String s,
                              String c)
Returns the index of the last ocurrence of the specified string. The search is performed backwards from the end of the string.

Parameters:
s - the string to be inspected
c - the string to be searched for
Returns:
the index of the last ocurrence of the specified string. If the specified string is not found -1 is returned.
See Also:
string

lastIndexOf

public static int lastIndexOf(String s,
                              char c,
                              int start,
                              boolean ignoreCase)
Returns the index of the last ocurrence of the specified character. The search is performed backwards from the specified starting position. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the character to be searched for
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the last ocurrence of the specified character. If the specified character is not found -1 is returned.
See Also:
string

lastIndexOf

public static int lastIndexOf(String s,
                              char c,
                              int start)
Returns the index of the last ocurrence of the specified character. The search is performed backwards from the specified starting position.

Parameters:
s - the string to be inspected
c - the character to be searched for
start - the starting position for the search
Returns:
the index of the last ocurrence of the specified character. If the specified character is not found -1 is returned.
See Also:
string

lastIndexOf

public static int lastIndexOf(String s,
                              char c)
Returns the index of the last ocurrence of the specified character. The search is performed backwards from the end of the string.

Parameters:
s - the string to be inspected
c - the string to be searched for
Returns:
the index of the last ocurrence of the specified character. If the specified character is not found -1 is returned.
See Also:
string

lastIndexOfAnyBut

public static int lastIndexOfAnyBut(String s,
                                    String c,
                                    int start,
                                    boolean ignoreCase)
Returns the index of the last character that is not contained in the specified set of characters. The search is performed backwards from the specified starting position. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the set of characters
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the last character that is not contained in the specified set of characters. If no such character is found -1 is returned.

lastIndexOfAnyBut

public static int lastIndexOfAnyBut(String s,
                                    String c,
                                    int start)
Returns the index of the last character that is not contained in the specified set of characters. The search is performed backwards from the specified starting position.

Parameters:
s - the string to be inspected
c - the set of characters
start - the starting position for the search
Returns:
the index of the last character that is not contained in the specified set of characters. If no such character is found -1 is returned.

lastIndexOfAnyBut

public static int lastIndexOfAnyBut(String s,
                                    String c)
Returns the index of the last character that is not contained in the specified set of characters. The search is performed backwards from the end of the string.

Parameters:
s - the string to be inspected
c - the set of characters
Returns:
the index of the last character that is not contained in the specified set of characters. If no such character is found -1 is returned.

lastIndexOfAnyOf

public static int lastIndexOfAnyOf(String s,
                                   String c,
                                   int start,
                                   boolean ignoreCase)
Returns the index of the last character that is contained in the specified set of characters. The search is performed backwards from the specified starting position. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the set of characters
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the last character that is contained in the specified set of characters. If no character from the string is in the specified set of characters -1 is returned.

lastIndexOfAnyOf

public static int lastIndexOfAnyOf(String s,
                                   String c,
                                   int start)
Returns the index of the last character that is contained in the specified set of characters. The search is performed backwards from the specified starting position.

Parameters:
s - the string to be inspected
c - the set of characters
start - the starting position for the search
Returns:
the index of the last character that is contained in the specified set of characters. If no character from the string is in the specified set of characters -1 is returned.

lastIndexOfAnyOf

public static int lastIndexOfAnyOf(String s,
                                   String c)
Returns the index of the last character that is contained in the specified set of characters. The search is performed backwards from the end of the string.

Parameters:
s - the string to be inspected
c - the set of characters
Returns:
the index of the last character that is contained in the specified set of characters. If no character from the string is in the specified set of characters -1 is returned.

stripLeading

public static String stripLeading(String s,
                                  String c,
                                  boolean ignoreCase)
Strips the specified leading characters. You can specify that case should be ignored.

Parameters:
s - the string of which the leading characters should be stripped off
c - the characters to be stripped off
ignoreCase - if true case is ignored when comparing characters
Returns:
the original string with the specified leading characters stripped off.

stripLeading

public static String stripLeading(String s,
                                  String c)
Strips the specified leading characters.

Parameters:
s - the string of which the leading characters should be stripped off
c - the characters to be stripped off
Returns:
the original string with the specified leading characters stripped off.

stripLeading

public static String stripLeading(String s,
                                  char c,
                                  boolean ignoreCase)
Strips the specified leading character. You can specify that case should be ignored.

Parameters:
s - the string of which the leading character should be stripped off
c - the character to be stripped off
ignoreCase - if true case is ignored when comparing characters
Returns:
the original string with the specified leading character stripped off.

stripLeading

public static String stripLeading(String s,
                                  char c)
Strips the specified leading character.

Parameters:
s - the string of which the leading character should be stripped off
c - the character to be stripped off
Returns:
the original string with the specified leading character stripped off.

stripLeadingBlanks

public static String stripLeadingBlanks(String s)
Strips leading white space characters. All characters for which Character#isWhitespace(char) returns true are considered white space characters.

Parameters:
s - the string of which white space is to be stripped off
Returns:
the original string with leading white space characters stripped off.
See Also:
Character.isWhitespace(char)

stripTrailing

public static String stripTrailing(String s,
                                   String c,
                                   boolean ignoreCase)
Strips the specified trailing characters. You can specify that case should be ignored.

Parameters:
s - the string of which trailing characters should be stripped off
c - the characters to be stripped off
ignoreCase - if true case is ignored when comparing characters
Returns:
the original string with the specified trailing characters stripped off.

stripTrailing

public static String stripTrailing(String s,
                                   String c)
Strips the specified trailing characters.

Parameters:
s - the string of which trailing characters should be stripped off
c - the characters to be stripped off
Returns:
the original string with the specified trailing characters stripped off.

stripTrailing

public static String stripTrailing(String s,
                                   char c,
                                   boolean ignoreCase)
Strips the specified trailing character. You can specify that case should be ignored.

Parameters:
s - the string of which the trailing character should be stripped off
c - the character to be stripped off
ignoreCase - if true case is ignored when comparing characters
Returns:
the original string with the specified trailing character stripped off.

stripTrailing

public static String stripTrailing(String s,
                                   char c)
Strips the specified trailing character.

Parameters:
s - the string of which trailing characters should be stripped off
c - the character to be stripped off
Returns:
the original string with the specified trailing character stripped off.

stripTrailingBlanks

public static String stripTrailingBlanks(String s)
Strips trailing white space characters. All characters for which Character#isWhitespace(char) returns true are considered white space characters.

Parameters:
s - the string of which white space is to be stripped off
Returns:
the original string with trailing white space characters stripped off.
See Also:
Character.isWhitespace(char)

strip

public static String strip(String s,
                           String c,
                           boolean ignoreCase)
Strips the specified characters from both ends of the string. You can specify that case should be ignored.

Parameters:
s - the string of which characters should be stripped off
c - the characters to be stripped off
ignoreCase - if true case is ignored when comparing characters
Returns:
the original string with the specified characters stripped off both ends.

strip

public static String strip(String s,
                           String c)
Strips the specified characters from both ends of the string.

Parameters:
s - the string of which characters should be stripped off
c - the characters to be stripped off
Returns:
the original string with the specified characters stripped off both ends.

strip

public static String strip(String s,
                           char c,
                           boolean ignoreCase)
Strips the specified character from both ends of the string. You can specify that case should be ignored.

Parameters:
s - the string of which the character should be stripped off
c - the character to be stripped off
ignoreCase - if true case is ignored when comparing characters
Returns:
the original string with the specified character stripped off both ends.

strip

public static String strip(String s,
                           char c)
Strips the specified character from both ends of the string.

Parameters:
s - the string of which the character should be stripped off
c - the character to be stripped off
Returns:
the original string with the specified character stripped off both ends.

stripBlanks

public static String stripBlanks(String s)
Strips white space characters from both ends of the string. All characters for which Character#isWhitespace(char) returns true are considered white space characters.

Parameters:
s - the string of which white space is to be stripped off
Returns:
the original string with white space stripped off both ends.
See Also:
Character.isWhitespace(char)

center

public static String center(String s,
                            int len,
                            char pad)
Centers the string within a string of the specified length, padding it with the specified character.

Parameters:
s - the original string
len - the length of the new string
pad - the pad character
Returns:
a string with the original string centered in it.

center

public static String center(String s,
                            int len)
Centers the string within a string of the specified length, padding it with blanks.

Parameters:
s - the original string
len - the length of the new string
Returns:
a string with the original string centered in it.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            int start,
                            int maxChanges,
                            boolean ignoreCase)
Changes occurrences of a specified pattern to a replacement string. The maximum number of changes and a starting position can be specified. You can specify that case should be ignored.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
start - the starting position for the search
maxChanges - the maximum number of changes
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            int start,
                            boolean ignoreCase)
Changes occurrences of a specified pattern to a replacement string. The starting position can be specified. You can specify that case should be ignored.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            int start,
                            int maxChanges)
Changes occurrences of a specified pattern to a replacement string. The maximum number of changes and a starting position can be specified.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
start - the starting position for the search
maxChanges - the maximum number of changes
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            int start)
Changes occurrences of a specified pattern to a replacement string. A starting position can be specified.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
start - the starting position for the search
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            boolean ignoreCase)
Changes occurrences of a specified pattern to a replacement string. You can specify that case should be ignored.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp)
Changes occurrences of a specified pattern to a replacement string.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            char oldc,
                            char newc,
                            int start,
                            int maxChanges,
                            boolean ignoreCase)
Changes occurrences of a specified character to a replacement character. The maximum number of changes and a starting position can be specified. You can specify that case should be ignored.

Parameters:
s - the input string
oldc - the pattern to be replaced
newc - the replacement string
start - the starting position for the search
maxChanges - the maximum number of changes
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified characters changed.

change

public static String change(String s,
                            char oldc,
                            char newc,
                            int start,
                            int maxChanges)
Changes occurrences of a specified character to a replacement character. The maximum number of changes and a starting position can be specified.

Parameters:
s - the input string
oldc - the pattern to be replaced
newc - the replacement string
start - the starting position for the search
maxChanges - the maximum number of changes
Returns:
a string with the specified characters changed.

change

public static String change(String s,
                            char oldc,
                            char newc,
                            int start,
                            boolean ignoreCase)
Changes occurrences of a specified character to a replacement character. The starting position can be specified. You can specify that case should be ignored.

Parameters:
s - the input string
oldc - the pattern to be replaced
newc - the replacement string
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified characters changed.

change

public static String change(String s,
                            char oldc,
                            char newc,
                            int start)
Changes occurrences of a specified character to a replacement character. A starting position can be specified.

Parameters:
s - the input string
oldc - the pattern to be replaced
newc - the replacement string
start - the starting position for the search
Returns:
a string with the specified characters changed.

change

public static String change(String s,
                            char oldc,
                            char newc)
Changes occurrences of a specified character to a replacement character.

Parameters:
s - the input string
oldc - the pattern to be replaced
newc - the replacement string
Returns:
a string with the specified characters changed.
See Also:
string

copies

public static String copies(String s,
                            int nCopies)
Returns a string consisting of the specified number of copies of the input string.

Parameters:
s - the input string
nCopies - the number of copies
Returns:
a string consisting of the specified number of copies of the input string.
See Also:
stringBuffer

insert

public static String insert(String s,
                            String ins,
                            int start,
                            char pad)
Inserts a string after the specified position. If the position is beyond the length of the original string, the result string is padded with the specified pad character.

Parameters:
s - the input string
ins - the string to be inserted
start - the starting position for the insert
pad - the pad character
Returns:
a string with the input string inserted after the specified position.

insert

public static String insert(String s,
                            String ins,
                            int start)
Inserts a string after the specified position. If the position is beyond the length of the original string, the result string is padded with blanks.

Parameters:
s - the input string
ins - the string to be inserted
start - the starting position for the insert
Returns:
a string with the input string inserted after the specified position.

leftJustify

public static String leftJustify(String s,
                                 int len,
                                 char pad)
Left-justifies the string in a string of the specified length. If the specified length is greater than the length of the string, the string is padded with the specified pad character.

Parameters:
s - the input string
len - the length of the new string
pad - the pad character
Returns:
a string with the input string left-justified in it.

leftJustify

public static String leftJustify(String s,
                                 int len)
Left-justifies the string in a string of the specified length. If the specified length is greater than the length of the string, the string is padded with blanks.

Parameters:
s - the input string
len - the length of the new string
Returns:
a string with the input string left-justified in it.

rightJustify

public static String rightJustify(String s,
                                  int len,
                                  char pad)
Right-justifies the string in a string of the specified length. If the specified length is greater than the length of the string, the string is padded with the specified pad character.

Parameters:
s - the input string
len - the length of the new string
pad - the pad character
Returns:
a string with the input string right-justified in it.

rightJustify

public static String rightJustify(String s,
                                  int len)
Right-justifies the string in a string of the specified length. If the specified length is greater than the length of the string, the string is padded with blanks.

Parameters:
s - the input string
len - the length of the new string
Returns:
a string with the input string right-justified in it.

toLowerCase

public static String toLowerCase(String s)
Converts the string to lower case.

Parameters:
s - the input string
Returns:
a string with all characters converted to lower case.
See Also:
string

toLowerCase

public static String toLowerCase(String s,
                                 Locale locale)
Converts the string to lower case using the given Locale.

Parameters:
s - the input string
Returns:
a string with all characters converted to lower case.
See Also:
string

toUpperCase

public static String toUpperCase(String s)
Converts the string to upper case.

Parameters:
s - the input string
Returns:
a string with all characters converted to upper case.
See Also:
string

toUpperCase

public static String toUpperCase(String s,
                                 Locale locale)
Converts the string to upper case using the given Locale.

Parameters:
s - the input string
Returns:
a string with all characters converted to upper case.
See Also:
string

toTitleCase

public static String toTitleCase(String s)
Converts the string to titlecase.

Parameters:
s - the input string
Returns:
a string with all characters converted to title case.
See Also:
Character.toTitleCase(char)

overlayWith

public static String overlayWith(String s,
                                 String o,
                                 int start,
                                 char pad)
Replaces part of the string with the specified string, starting at a specified position. If the starting position is beyond the end of the string, it is padded with the specified pad character.

Parameters:
s - the original string
o - the string to be overlayed over the original string
start - the starting position for the overlay
pad - the padding character
Returns:
a string with part of it replaced by the overlay string.

overlayWith

public static String overlayWith(String s,
                                 String o,
                                 int start)
Replaces part of the string with the specified string, starting at a specified position. If the starting position is beyond the end of the string, it is padded with blanks.

Parameters:
s - the original string
o - the string to be overlayed over the original string
start - the starting position for the overlay
Returns:
a string with part of it replaced by the overlay string.

remove

public static String remove(String s,
                            int start,
                            int numChars)
Removes the specified number of characters from the string, starting at the specified position.

Parameters:
s - the original string
start - the starting position
numChars - the number of characters to be removed
Returns:
a string with the specified number of characters removed.

substring

public static String substring(String s,
                               int start,
                               int len,
                               char pad)
Returns a substring of the specified string, starting at a specified position, with the specified length. If the specified length reaches beyond the length of the string, the result is padded with the specified pad character.

Parameters:
s - the original string
start - the starting position
len - the length of the substring
pad - the padding character
Returns:
a substring of the input string.
Throws:
StringIndexOutOfBoundsException - if start is out of range or len is less than zero.
See Also:
string

substring

public static String substring(String s,
                               int start,
                               int len)
Returns a substring of the specified string, starting at a specified position, with the specified length. If the specified length reaches beyond the length of the string, the result is padded with blanks.

Parameters:
s - the original string
start - the starting position
len - the length of the substring
Returns:
a substring of the input string.
Throws:
StringIndexOutOfBoundsException - if start is out of range.
See Also:
string

substring

public static String substring(String s,
                               int start)
Returns a substring of the specified string, starting at a specified position, and extending to the end of the string.

Parameters:
s - the original string
start - the starting position
Returns:
a substring of the input string.
Throws:
StringIndexOutOfBoundsException - if start is out of range.
See Also:
string

reverse

public static String reverse(String s)
Reverses the sequence of characters contained in the string.

Parameters:
s - the original string
Returns:
a string with the characters from the original string reversed.
See Also:
stringBuffer

translate

public static String translate(String s,
                               String setin,
                               String setout,
                               char pad,
                               boolean ignoreCase)
Converts all of the string's characters which are contained in the input set of characters to the corresponding character in the output set of characters. If the output set of characters is shorter than the input set of characters, it is padded with the specified pad character. You can specify that case should be ignored. The method can be used to reorder characters in a string: Strings.translate("3421", "1234", "abcd", ' ') returns "cdba"

Parameters:
s - the original string
setin - the input set of characters
setout - the output set of characters
pad - the pad character
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified characters tramslated.

translate

public static String translate(String s,
                               String setin,
                               String setout,
                               char pad)
Converts all of the string's characters which are contained in the input set of characters to the corresponding character in the output set of characters. If the output set of characters is shorter than the input set of characters, it is padded with the specified pad character. The method can be used to reorder characters in a string: Strings.translate("3421", "1234", "abcd", ' ') returns "cdba"

Parameters:
s - the original string
setin - the input set of characters
setout - the output set of characters
pad - the pad character
Returns:
a string with the specified characters tramslated.

translate

public static String translate(String s,
                               String setin,
                               String setout,
                               boolean ignoreCase)
Converts all of the string's characters which are contained in the input set of characters to the corresponding character in the output set of characters. If the output set of characters is shorter than the input set of characters, it is padded with blanks. You can specify that case should be ignored. The method can be used to reorder characters in a string: Strings.translate("3421", "1234", "abcd", ' ') returns "cdba"

Parameters:
s - the original string
setin - the input set of characters
setout - the output set of characters
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified characters tramslated.

translate

public static String translate(String s,
                               String setin,
                               String setout)
Converts all of the string's characters which are contained in the input set of characters to the corresponding character in the output set of characters. If the output set of characters is shorter than the input set of characters, it is padded with blanks. The method can be used to reorder characters in a string: Strings.translate("3421", "1234", "abcd") returns "cdba"

Parameters:
s - the original string
setin - the input set of characters
setout - the output set of characters
Returns:
a string with the specified characters tramslated.

xRange

public static String xRange(char start,
                            char end)
Builds a string consisting of all characters between 'start' and 'end'. Both the start and end characters are included in the string.

Parameters:
start - the starting character
end - the ending character
Returns:
a string consisting of all the specified characters.

contains

public static boolean contains(String s,
                               String search,
                               boolean ignoreCase)
Returns true if the specified search string is contained in the original string. You can specify that case should be ignored.

Parameters:
s - the input string
search - the search string
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the search string is contained in the input string
See Also:
string

contains

public static boolean contains(String s,
                               String search)
Returns true if the specified search string is contained in the original string.

Parameters:
s - the original string
search - the search string
Returns:
true if the search string is contained in the input string
See Also:
string

isAbbreviationOf

public static boolean isAbbreviationOf(String s,
                                       String full,
                                       int minLength,
                                       boolean ignoreCase)
Returns true if the string is a valid abbreviation of another string. A string s is considered an abbreviation of another string full if the string s is a prefix of string full and its length is at least minLength. You can specify that case should be ignored.

Parameters:
s - the string to test
full - the full string
minLength - the minimum length
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the string s is an abbreviation of string full.

isAbbreviationOf

public static boolean isAbbreviationOf(String s,
                                       String full,
                                       int minLength)
Returns true if the string is a valid abbreviation of another string. A string s is considered an abbreviation of another string full if the string s is a prefix of string full and its length is at least minLength.

Parameters:
s - the string to test
full - the full string
minLength - the minimum length
Returns:
true if the string s is an abbreviation of string full.

isAbbreviationOf

public static boolean isAbbreviationOf(String s,
                                       String full,
                                       boolean ignoreCase)
Returns true if the string is a valid abbreviation of another string. A string s is considered an abbreviation of another string full if the string s is a prefix of string full. You can specify that case should be ignored.

Parameters:
s - the string to test
full - the full string
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the string s is an abbreviation of string full.
See Also:
string

isLike

public static boolean isLike(String s,
                             String pattern,
                             int start,
                             char wAnySeq,
                             char wAnyChar,
                             boolean ignoreCase)
Returns true if the string matches the specified pattern. The pattern may contain two wildcard characters, where the first wildcard character matches any sequence of characters and the second wildcard character matches an arbitrary single character. You can specify that case should be ignored.

Parameters:
s - the string to test
pattern - the pattern string
start - the starting position
wAnySeq - the wildcard character which matches any sequence of characters
wAnyChar - the wildcard character which matches any character
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the string matches the specified pattern.

isLike

public static boolean isLike(String s,
                             String pattern,
                             int start,
                             boolean ignoreCase)
Returns true if the string matches the specified pattern. The pattern may contain two wildcard characters, where '*' matches any sequence of characters and '?' matches an arbitrary single character. You can specify that case should be ignored.

Parameters:
s - the string to test
pattern - the pattern string
start - the starting position
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the string matches the specified pattern.

isLike

public static boolean isLike(String s,
                             String pattern,
                             int start)
Returns true if the string matches the specified pattern. The pattern may contain two wildcard characters, where '*' matches any sequence of characters and '?' matches an arbitrary single character.

Parameters:
s - the string to test
pattern - the pattern string
start - the starting position
Returns:
true if the string matches the specified pattern.

isLike

public static boolean isLike(String s,
                             String pattern)
Returns true if the string matches the specified pattern. The pattern may contain two wildcard characters, where '*' matches any sequence of characters and '?' matches an arbitrary single character.

Parameters:
s - the string to test
pattern - the pattern string
Returns:
true if the string matches the specified pattern.

indexOfWord

public static int indexOfWord(String s,
                              int wordNum)
Returns the index of the first character of the specified nth word within the string. Word numbers start at 0. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true.

Parameters:
s - the input string
wordNum - the number of the word
Returns:
the index of the first character of the specified nth word within the string. Returns -1 if the word is not found.

indexOfPhrase

public static int indexOfPhrase(String s,
                                String p,
                                int startWord,
                                boolean ignoreCase)
Returns the index of the first occurrence of the specified phrase within the string. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true. You can specify that case should be ignored.

Parameters:
s - the input string
p - the phrase to be searched for
startWord - the word number where the search is to start. The first word has number 0.
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first occurrence of the specified phrase within the string. Returns -1 if the phrase is not found.

indexOfPhrase

public static int indexOfPhrase(String s,
                                String p,
                                int startWord)
Returns the index of the first occurrence of the specified phrase within the string. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true.

Parameters:
s - the input string
p - the phrase to be searched for
startWord - the word number where the search is to start. The first word has number 0.
Returns:
the index of the first occurrence of the specified phrase within the string. Returns -1 if the phrase is not found.

numWords

public static int numWords(String s)
Returns the number of words in the string. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true.

Parameters:
s - the input string
Returns:
the number of words in the string.

removeWords

public static String removeWords(String s,
                                 int startWord,
                                 int numWords)
Removes the specified number of words from the string, starting with the specified word number. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true.

Parameters:
s - the input string
startWord - the number of the first word to be removed
numWords - the number of words to be removed.
Returns:
a string with the specified number of words removed.

wordSpace

public static String wordSpace(String s,
                               int spaces)
All whitespace between the words of the string is replaced by the specified number of blanks. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true.

Parameters:
s - the input string
spaces - the number of blanks between the words
Returns:
a string with the words separated by the specifed number of blanks

word

public static String word(String s,
                          int wordNum)
Returns the nth word in the string. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true.

Parameters:
s - the input string
wordNum - the number of the word to be returned
Returns:
a string representing the nth word from the input string.

wordIndexOfPhrase

public static int wordIndexOfPhrase(String s,
                                    String p,
                                    int startWord,
                                    boolean ignoreCase)
Returns the number of the first word of the first occurrence of the specified phrase within the string. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true. You can specify that case should be ignored.

Parameters:
s - the input string
p - the phrase to be searched for
startWord - the word number where the search is to start. The first word has number 0.
ignoreCase - if true case is ignored when comparing characters
Returns:
the number of the first word of the first occurrence of the specified phrase within the string.

wordIndexOfPhrase

public static int wordIndexOfPhrase(String s,
                                    String p,
                                    int startWord)
Returns the number of the first word of the first occurrence of the specified phrase within the string. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true.

Parameters:
s - the input string
p - the phrase to be searched for
startWord - the word number where the search is to start. The first word has number 0.
Returns:
the number of the first word of the first occurrence of the specified phrase within the string.

subWords

public static String subWords(String s,
                              int startWord,
                              int numWords)
Returns a substring of the string which starts at a specified word and contains the specified number of words. Words are sequences of characters separated by white space. White space is any character for which java.lang.Character#isWhitespace(char) returns true.

Parameters:
s - the input string
startWord - the word number of the first word
numWords - the number of words to be returned
Returns:
a substring of the input string containing the specified number of words.

split

public static String[] split(String s)
Return an array of the constituent words of a string. Words are bounded byte sequences of whitespace. Whitespace characters are those for which java.lang.Character#isWhitespace(char) returns true. (Contributed by Eric Jablow)

Parameters:
s - The string to split into its constituent words.
Returns:
Array of the constituent words of s.

split

public static String[] split(String s,
                             int limit)
Return an array of (at most) the first limit constituent words of a string. Words are bounded byte sequences of whitespace. Whitespace characters are those for which java.lang.Character#isWhitespace(char) returns true. (Contributed by Eric Jablow)

Parameters:
s - The string to split into its constituent words.
limit - The maximum number of words to return.
Returns:
Array of the constituent words of s.

toBoolean

public static boolean toBoolean(String s)
Returns true if the string represents the word "true".

Parameters:
s - the input string
Returns:
true if the string contains the characters "true" (ignoring case).
See Also:
Boolean.valueOf(String).

toByte

public static byte toByte(String s)
                   throws NumberFormatException
If the string represents a valid byte value, returns this value as a byte.

Parameters:
s - the input string
Returns:
the value of the string represented as a byte.
Throws:
NumberFormatException - if the string cannot be represented as a byte.
See Also:
Byte.valueOf(String).

toByte

public static byte toByte(String s,
                          int radix)
                   throws NumberFormatException
If the string represents a valid byte value, returns this value as a byte. You can specify the desired radix.

Parameters:
s - the input string
radix - the radix of the number
Returns:
the value of the string represented as a byte.
Throws:
NumberFormatException - if the string cannot be represented as a byte.
See Also:
Byte.valueOf(String, int).

toShort

public static short toShort(String s,
                            int radix)
                     throws NumberFormatException
If the string represents a valid short number, returns this number as a short value. You can specify the desired radix.

Parameters:
s - the input string
radix - the radix of the number
Returns:
the value of the string represented as a short.
Throws:
NumberFormatException - if the string cannot be represented as a short.
See Also:
Short.valueOf(String).

toShort

public static short toShort(String s)
                     throws NumberFormatException
If the string represents a valid short number, returns this number as a short value.

Parameters:
s - the input string
Returns:
the value of the string represented as a short.
Throws:
NumberFormatException - if the string cannot be represented as a short.
See Also:
Short.valueOf(String, int).

toInt

public static int toInt(String s)
                 throws NumberFormatException
If the string represents a valid integer number, returns this number as an int value.

Parameters:
s - the input string
Returns:
the value of the string represented as an int.
Throws:
NumberFormatException - if the string cannot be represented as an int.
See Also:
Integer.valueOf(String).

toInt

public static int toInt(String s,
                        int radix)
                 throws NumberFormatException
If the string represents a valid integer number, returns this number as an int value. You can specify the desired radix.

Parameters:
s - the input string
radix - the radix of the number
Returns:
the value of the string represented as an int.
Throws:
NumberFormatException - if the string cannot be represented as an int.
See Also:
Integer.valueOf(String, int).

toLong

public static long toLong(String s)
                   throws NumberFormatException
If the string represents a valid long integer, returns this number as a long value.

Parameters:
s - the input string
Returns:
the value of the string represented as a long.
Throws:
NumberFormatException - if the string cannot be represented as a long.
See Also:
Long.valueOf(String).

toLong

public static long toLong(String s,
                          int radix)
                   throws NumberFormatException
If the string represents a valid long integer, returns this number as a long value. You can specify the desired radix.

Parameters:
s - the input string
radix - the radix of the number
Returns:
the value of the string represented as a long.
Throws:
NumberFormatException - if the string cannot be represented as a long.
See Also:
Long.valueOf(String, int).

toFloat

public static float toFloat(String s)
                     throws NumberFormatException
If the string represents a valid float number, returns this number as a float value.

Parameters:
s - the input string
Returns:
the value of the string represented as a float.
Throws:
NumberFormatException - if the string cannot be represented as a float.
See Also:
Float.valueOf(String).

toDouble

public static double toDouble(String s)
                       throws NumberFormatException
If the string represents a valid double number, returns this number as a double value.

Parameters:
s - the input string
Returns:
the value of the string represented as a double.
Throws:
NumberFormatException - if the string cannot be represented as a double.
See Also:
Double.valueOf(String).

isDigit

public static boolean isDigit(String s)
Returns true if the string consists of digits.

Parameters:
s - the input string
Returns:
true if the string consists only of digits.
See Also:
Character.isDigit(char).

isIdentifierIgnorable

public static boolean isIdentifierIgnorable(String s)
Returns true if the string consists of ignorable characters in a Java identifier or a Unicode identifier.

Parameters:
s - the input string
Returns:
true if the string consists only of ignorable characters in a Java identifier or a Unicode identifier.
See Also:
Character.isIdentifierIgnorable(char).

isISOControl

public static boolean isISOControl(String s)
Returns true if the string consists of ISO control characters.

Parameters:
s - the input string
Returns:
true if the string consists only of ISO control characters.
See Also:
Character.isISOControl(char).

isJavaIdentifier

public static boolean isJavaIdentifier(String s)
Returns true if the string is a valid Java identifier.

Parameters:
s - the input string
Returns:
true if the string is a valid Java identifier.
See Also:
Character.isJavaIdentifierStart(char), Character.isJavaIdentifierPart(char).

isLetter

public static boolean isLetter(String s)
Returns true if the string consists of letters.

Parameters:
s - the input string
Returns:
true if the string consists only of letters.
See Also:
Character.isLetter(char).

isLetterOrDigit

public static boolean isLetterOrDigit(String s)
Returns true if the string consists of letters or digits.

Parameters:
s - the input string
Returns:
true if the string consists only of letters or digits.
See Also:
Character.isLetterOrDigit(char).

isLowerCase

public static boolean isLowerCase(String s)
Returns true if the string consists of lowercase characters.

Parameters:
s - the input string
Returns:
true if the string consists only of lowercase characters.
See Also:
Character.isLowerCase(char).

isSpaceChar

public static boolean isSpaceChar(String s)
Returns true if the string consists of Unicode space characters.

Parameters:
s - the input string
Returns:
true if the string consists only of Unicode space characters.
See Also:
Character.isSpaceChar(char).

isTitleCase

public static boolean isTitleCase(String s)
Returns true if the string consists of title case characters.

Parameters:
s - the input string
Returns:
true if the string consists only of Unicode title case characters.
See Also:
Character.isTitleCase(char).

isUnicodeIdentifier

public static boolean isUnicodeIdentifier(String s)
Returns true if the string is a valid Unicode identifier.

Parameters:
s - the input string
Returns:
true if the string is a valid Unicode identifier.
See Also:
Character.isJavaIdentifierStart(char), Character.isJavaIdentifierPart(char)

isUpperCase

public static boolean isUpperCase(String s)
Returns true if the string consists of uppercase characters.

Parameters:
s - the input string
Returns:
true if the string consists only of uppercase characters.
See Also:
Character.isUpperCase(char).

isWhitespace

public static boolean isWhitespace(String s)
Returns true if the string consists of whitespace characters.

Parameters:
s - the input string
Returns:
true if the string consists only of whitespace characters.
See Also:
Character.isWhitespace(char).