|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dsto.dfc.text.StringUtility
public final class StringUtility
Utilities for manipulating strings.
Method Summary | |
---|---|
static String |
capitaliseAllWords(String title)
Capitalises all characters preceeded by a space, plus the first character of sentence . |
static String |
capitaliseFirst(String str)
Capitalise the first character of a string. |
static String |
characters(char c,
int count)
Generate a string containing count number of character c. |
static String |
escapeCharacters(String str,
String chars)
Escape a given set of special characters in a string using '\' as the escape character. |
static String |
escapeCharacters(String str,
String chars,
char escapeChar)
Escape a given set of special characters in a string. |
static String |
expandSymbols(String str,
Map symbols)
Expand symbolic variables embedded within a string. |
static String |
expandSymbols(String str,
Map symbols,
String symbolPrefixes,
boolean useDelimeters)
Expand symbolic variables embedded within a string. |
static Object |
fromString(Class type,
String string)
Uses translatorFor(Class) to convert a string to a given
value. |
static boolean |
hasTranslatorFor(Class type)
Shortcut to test whether a translator is registered for a given type. |
static int |
indexOfChar(String str,
String chars)
Return the first character index in a string that is one of a specified set of characters. |
static int |
indexOfChar(String str,
String chars,
int start)
Return the first character index in a string that is one of a specified set of characters. |
static boolean |
isHexString(String string)
Test of string contains only hexadecimal characters (0-9,a-f). |
static String |
join(List strings,
String delimiter)
Join an array of objects into single string. |
static String |
join(Object[] objects,
String delimiter)
Join an array of objects into single string. |
static String |
replace(String srcString,
String replaceStr,
String replaceWithStr)
Replace all occurrences of one string with another. |
static String[] |
split(String str)
|
static String[] |
split(String string,
char[] delimiters)
Splits a String up using the delimiter chars in
delimiters into an array of Strings . |
static String[] |
split(String string,
char[] delimiters,
boolean includeDelimiters)
Splits a String up using the delimiter chars in
delimiters into an array of Strings . |
static String[] |
split(String str,
String delimiter)
Split a string into an array of substrings using a delimiter. |
static String |
toString(Object value)
Uses translatorFor(Class) to convert a value to a
string. |
static IStringTranslator |
translatorFor(Class type)
Get a registered string translator for a given type. |
static String |
truncate(String string,
int maxLength)
Truncate a string to a given max length. |
static String |
wordifyCaps(String str)
Turn a string like "HelloThereFrodo" into "Hello There Frodo". |
static String |
wrappedHtml(String string,
int width)
Convert the given string into a multi-line word-wrapped string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static String[] split(String str)
public static String[] split(String str, String delimiter)
NB This is different to (JDK1.4+)
String.split(String)
for which the delimiter parameter is, in fact, a regular
expression.
join(Object[], String)
,
String.split(java.lang.String)
public static String[] split(String string, char[] delimiters)
String
up using the delimiter chars in
delimiters
into an array of Strings
.
The delimiters are included in the Strings
by
default.
string
- The String
to split up.delimiters
- The delimiter chars to use.
Strings
, which include the
delimiter chars.split(String, char[], boolean)
public static String[] split(String string, char[] delimiters, boolean includeDelimiters)
String
up using the delimiter chars in
delimiters
into an array of Strings
.
The delimiters are included in the Strings
if
includeDelimiters
is true.
string
- The String
to split up.delimiters
- The delimiter chars to use.includeDelimiters
- If true, the delimiters are included in the
resulting Strings
.
Strings
, which may or may not
include the delimiter chars depending on if
includeDelimiters
is true or false.split(String, char[])
public static String join(Object[] objects, String delimiter)
objects
- The objects to join.delimiter
- The string to add between each pair of strings.split(java.lang.String)
public static String join(List strings, String delimiter)
strings
- The objects to join.delimiter
- The string to add between each pair of strings.split(java.lang.String)
public static String capitaliseFirst(String str)
public static String replace(String srcString, String replaceStr, String replaceWithStr)
srcString
- The string to be transformed.replaceStr
- The string to replace.replaceWithStr
- The string to replace all occurrences of
replaceStr.
public static String expandSymbols(String str, Map symbols)
str
- The string to expand.symbols
- The symbol definitions.
public static String expandSymbols(String str, Map symbols, String symbolPrefixes, boolean useDelimeters)
symbols.get ("var")
or ""
if var is not defined in the property set.
str
- The string to expand.symbols
- The symbol definitions.symbolPrefixes
- The set of character prefixes that
variables may begin with (eg "$%").useDelimeters
- True if {}'s are allowed as symbol name
delimeters, allowing multi-character names. When true,
single character symbols may still be specified without
{}'s.
public static int indexOfChar(String str, String chars)
str
- The string to search.chars
- The set of characters to match.
indexOfChar(String, String, int)
public static int indexOfChar(String str, String chars, int start)
str
- The string to search.chars
- The set of characters to match.start
- The starting index to search from.
public static String wordifyCaps(String str)
public static boolean isHexString(String string)
public static String escapeCharacters(String str, String chars)
str
- The string to escape.chars
- The set of special characters to escape (eg "'). The escape
character itself is implicitly part of this set.
escapeCharacters(String, String, char)
public static String escapeCharacters(String str, String chars, char escapeChar)
str
- The string to escape.chars
- The set of special characters to escape (eg "'). The escape
character itself is implicitly part of this set.escapeChar
- The escape character (eg '\').
public static String truncate(String string, int maxLength)
string
- The string to truncate. May be null.maxLength
- The max length of the returned string. If longer, the
string is truncated with "...". The minimum string length will never be
less than 3.public static String capitaliseAllWords(String title)
sentence
.
title
- The sentence, each word of which to capitalise.
sentence
, but with each word capitalised.public static String characters(char c, int count)
public static Object fromString(Class type, String string) throws InvalidFormatException
translatorFor(Class)
to convert a string to a given
value.
type
- The target type to convert to.string
- The string to convert.
InvalidFormatException
- if an error occurs parsing.public static String toString(Object value) throws IllegalArgumentException
translatorFor(Class)
to convert a value to a
string. This may be different from simply calling toString()
depending on which translator is registered for the value class.
value
- The value to covert.
IllegalArgumentException
- if value has no associated
translator.public static boolean hasTranslatorFor(Class type)
translatorFor(Class)
public static IStringTranslator translatorFor(Class type) throws IllegalArgumentException
type
- The type to look for.
IllegalArgumentException
- if there is no translator for
type.hasTranslatorFor(Class)
public static String wrappedHtml(String string, int width)
string
- The string to word wrapwidth
- The interval used to wrap words
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |