ix.util
Class Strings

java.lang.Object
  |
  +--ix.util.Strings

public final class Strings
extends java.lang.Object

A class containing useful static string methods.


Method Summary
static java.lang.String afterLast(java.lang.String separator, java.lang.String s)
          Returns the substring starting directly after the last occurrence of the separator.
static java.lang.String beforeFirst(java.lang.String separator, java.lang.String s)
          Returns the substring that ends directly before the first occurrence of the separator.
static java.util.List breakAt(java.lang.String separator, java.lang.String s)
          Returns a list of the substrings delimited by the given separator.
static java.lang.String[] breakAtFirst(java.lang.String separator, java.lang.String s)
          breakAtFirst takes a string containing fields separated by a (string) delimiter and returns a two-element string array containing the substring before the first occurrence of the char and the substring after.
static java.util.List breakIntoLines(java.lang.String text)
          Returns a List of the lines in a string.
static java.lang.String capitalize(java.lang.String s)
          Returns a copy of the string in which the first character is in upper case and the rest of the string is left as it was.
static java.lang.String dashNameToJavaName(java.lang.String name)
          Converts a name in which words are separate by dashes into one that uses Java-style capitalisation instead.
static java.lang.String firstLine(java.lang.String s)
          Returns the first line of a string.
static java.lang.String foldLongLine(java.lang.String text)
          Replaces some spaces with line separators to make a long string more readable in contexts where it would have been displayed as a single line.
static int indexOfAny(java.lang.String chars, int start, java.lang.String s)
          Returns the index of the first occurrence of any of the specified characters, or -1 if none are found.
static int indexOfAny(java.lang.String chars, java.lang.String s)
          Returns the index of the first occurrence of any of the specified characters, or -1 if none are found.
static java.lang.String javaNameToDashName(java.lang.String name)
          Converts a name that shows word boundaries using Java-style capitalization to a name in which words are all lower case and separated by dashes.
static java.lang.String quote(java.lang.String text)
          Puts double quotes around a string.
static java.lang.String repeat(int count, java.lang.String s)
          Returns a String made by appending a specified string count times.
static java.lang.String replace(java.lang.String from, java.lang.String to, java.lang.String source)
          Returns a string formed by replacing every occurrence of from with to in source.
static java.lang.String uncapitalize(java.lang.String s)
          Returns a copy of the string in which the first character is in lower case and the rest of the string is left as it was.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

indexOfAny

public static int indexOfAny(java.lang.String chars,
                             java.lang.String s)
Returns the index of the first occurrence of any of the specified characters, or -1 if none are found.
Parameters:
chars - the characters to look for
s - the string to look in

indexOfAny

public static int indexOfAny(java.lang.String chars,
                             int start,
                             java.lang.String s)
Returns the index of the first occurrence of any of the specified characters, or -1 if none are found.
Parameters:
chars - the characters to look for
start - index to start looking
s - the string to look in

breakAtFirst

public static java.lang.String[] breakAtFirst(java.lang.String separator,
                                              java.lang.String s)
breakAtFirst takes a string containing fields separated by a (string) delimiter and returns a two-element string array containing the substring before the first occurrence of the char and the substring after. Neither substring contains the delimiter. If the delimiter does not appear in the string at all, the values are the string and "".
Parameters:
separator - the delimiter
s - the string that may contain it

breakAt

public static java.util.List breakAt(java.lang.String separator,
                                     java.lang.String s)
Returns a list of the substrings delimited by the given separator. The separator itself does not appear in any element of the list, and if the separator does not occur, the reault is a one-element list containing the string as-is.
Parameters:
separator - the delimiter
s - the string that may contain it

beforeFirst

public static java.lang.String beforeFirst(java.lang.String separator,
                                           java.lang.String s)
Returns the substring that ends directly before the first occurrence of the separator. If the separator does not occur, the entire string is returned as-is.
Parameters:
separator - the delimiter
s - the string that may contain it

afterLast

public static java.lang.String afterLast(java.lang.String separator,
                                         java.lang.String s)
Returns the substring starting directly after the last occurrence of the separator. If the separator does not occur, the entire string is returned as-is.
Parameters:
separator - the delimiter
s - the string that may contain it

firstLine

public static java.lang.String firstLine(java.lang.String s)
Returns the first line of a string.

breakIntoLines

public static java.util.List breakIntoLines(java.lang.String text)
Returns a List of the lines in a string.

foldLongLine

public static java.lang.String foldLongLine(java.lang.String text)
Replaces some spaces with line separators to make a long string more readable in contexts where it would have been displayed as a single line.

replace

public static java.lang.String replace(java.lang.String from,
                                       java.lang.String to,
                                       java.lang.String source)
Returns a string formed by replacing every occurrence of from with to in source. If any replacements are made, the result is a new string without any modifications to the original. If, on the other hand, from does not occur, the original string is returned rather than a copy.
Parameters:
from - the text to replace
to - the text to replace it with
source - the text in which to do the replacing
Returns:
a new string if any replacements were needed; otherwise the original source string.

quote

public static java.lang.String quote(java.lang.String text)
Puts double quotes around a string. This is useful to indicate the boundaries of the string when it's included in other text such as in an error or warning message.

capitalize

public static java.lang.String capitalize(java.lang.String s)
Returns a copy of the string in which the first character is in upper case and the rest of the string is left as it was.

uncapitalize

public static java.lang.String uncapitalize(java.lang.String s)
Returns a copy of the string in which the first character is in lower case and the rest of the string is left as it was.

repeat

public static java.lang.String repeat(int count,
                                      java.lang.String s)
Returns a String made by appending a specified string count times.

dashNameToJavaName

public static java.lang.String dashNameToJavaName(java.lang.String name)
Converts a name in which words are separate by dashes into one that uses Java-style capitalisation instead.

javaNameToDashName

public static java.lang.String javaNameToDashName(java.lang.String name)
Converts a name that shows word boundaries using Java-style capitalization to a name in which words are all lower case and separated by dashes.
See Also:
JavaNameWordIterator