@ComponentSpecification public interface StringUtil
String
handling and manipulation.StringUtilImpl.getInstance()
,
UnicodeUtil
Modifier and Type | Field and Description |
---|---|
static char[] |
EMPTY_CHAR_ARRAY
An empty char array.
|
static String[] |
EMPTY_STRING_ARRAY
An empty
String array. |
static String |
FALSE
a string representing the boolean value
false |
static String |
LINE_SEPARATOR
The platform-specific line-separator string.
|
static String |
LINE_SEPARATOR_CR
The line-separator with a single carriage-return.
|
static String |
LINE_SEPARATOR_CRLF
The Windows line-separator (carriage-return line-feed).
|
static String |
LINE_SEPARATOR_LF
The Unix line-separator (line-feed).
|
static String |
LINE_SEPARATOR_LFCR
The Mac line-separator (line-feed carriage-return).
|
static String |
NULL
a string representing the undefined value
null . |
static String |
SYSTEM_PROPERTY_LINE_SEPARATOR
The
system property name for LINE_SEPARATOR . |
static String |
TRUE
a string representing the boolean value
true |
Modifier and Type | Method and Description |
---|---|
String |
fromCamlCase(String string,
char separator)
This method converts the given
string from caml-case syntax to lower-case using the given separator
as word-boundary. |
List<String> |
fromSeparatedString(CharSequence separatedString,
String separator,
StringSyntax syntax)
This method is like
fromSeparatedString(CharSequence, String, StringSyntax, Collection, ValueConverter)
but expects elements of the type String that do not need additional custom conversion. |
<E> void |
fromSeparatedString(CharSequence separatedString,
String separator,
StringSyntax syntax,
Collection<E> collection,
ValueConverter<? super String,? super E> converter,
Class<E> type)
This method parses the given
separatedString that contains elements separated with separator and
the given syntax and adds these elements to the given collection . |
<E> void |
fromSeparatedString(CharSequence separatedString,
String separator,
StringSyntax syntax,
Collection<E> collection,
ValueConverter<String,E> converter)
This method parses the given
separatedString that contains elements separated with separator and
the given syntax and adds these elements to the given collection . |
void |
fromSeparatedString(CharSequence separatedString,
String separator,
StringSyntax syntax,
Collection<String> collection)
This method is like
fromSeparatedString(CharSequence, String, StringSyntax, Collection, ValueConverter)
but expects elements of the type String that do not need additional custom conversion. |
String |
getLineSeparator()
The platform-specific line-separator string.
|
boolean |
isAllLowerCase(String string)
Determines if all characters of the given
string are in lower case . |
boolean |
isAllUpperCase(String string)
Determines if all characters of the given
string are in upper case . |
boolean |
isEmpty(String string)
This method determines if the given string contains no information.
|
boolean |
isEmpty(String string,
boolean trim)
This method determines if the given string is empty.
|
boolean |
isSubstring(char[] string,
String substring,
int offset)
|
boolean |
isSubstring(String string,
String substring,
int offset)
|
String |
padNumber(long number,
int digits)
This method formats a positive number to a string with at least the given number of digits padding it with leading
zeros.
|
String |
padNumber(long number,
int digits,
int radix)
This method formats a positive number to a string using the given
radix with at least the given number of
digits padding it with leading zeros. |
Boolean |
parseBoolean(String booleanValue)
This method parses a boolean value given as string.
|
void |
replace(char[] string,
char oldChar,
char newChar)
This method replaces all occurrences of
oldChar in the char-array given by string with
newChar . |
String |
replace(String string,
String match,
String replace)
This method replaces all occurrences of the string
match with the string replace in the given
string. |
String |
replaceSuffixWithCase(String string,
int suffixLength,
String newSuffixLowerCase)
This method delegates to
replaceSuffixWithCase(String, int, String, Locale) using Locale.ENGLISH . |
String |
replaceSuffixWithCase(String string,
int suffixLength,
String newSuffixLowerCase,
Locale locale)
This method replaces the last
suffixLength number of characters from string with the lower-case
string newSuffixLowerCase with respect to the original case of the given string . |
String |
toCamlCase(String string)
This method converts the given
string to caml-case syntax using the default separators ' ' ,
'-' , '_' and '.' . |
String |
toCamlCase(String string,
char... separators)
This method converts the given
string to caml-case syntax. |
String |
toSeparatedString(Collection<?> collection,
String separator,
StringSyntax syntax)
This method formats the elements given by
collection to a string where each value is formatted to its
string representation and separated by separator . |
<E> String |
toSeparatedString(Collection<E> collection,
String separator,
StringSyntax syntax,
Formatter<E> formatter)
This method is like
toSeparatedString(Collection, String, StringSyntax) but allows to specify an explicit
Formatter to use instead of Object.toString() . |
<E> void |
toSeparatedString(Collection<E> collection,
String separator,
StringSyntax syntax,
Formatter<E> formatter,
Appendable buffer)
This method is like
toSeparatedString(Collection, String, StringSyntax) but allows to specify an explicit
Formatter to use instead of Object.toString() . |
static final String TRUE
true
static final String FALSE
false
static final String NULL
null
.static final String LINE_SEPARATOR_CR
static final String LINE_SEPARATOR_LF
static final String LINE_SEPARATOR_CRLF
static final String LINE_SEPARATOR_LFCR
static final String LINE_SEPARATOR
LINE_SEPARATOR_LF
,
LINE_SEPARATOR_CRLF
, LINE_SEPARATOR_LFCR
, LINE_SEPARATOR_CR
.static final String SYSTEM_PROPERTY_LINE_SEPARATOR
system property name
for LINE_SEPARATOR
.static final char[] EMPTY_CHAR_ARRAY
String getLineSeparator()
LINE_SEPARATOR_LF
,
LINE_SEPARATOR_CRLF
, LINE_SEPARATOR_LFCR
, LINE_SEPARATOR_CR
.Boolean parseBoolean(String booleanValue)
booleanValue
- is the boolean value as string.true
if the given string equals
to true
, false
if it equals
to false
and null
in any other case.Boolean.valueOf(String)
void replace(char[] string, char oldChar, char newChar)
oldChar
in the char-array given by string
with
newChar
.string
- is the char-array where the replacement should take place.oldChar
- is the character to be replaced.newChar
- is the replacement for oldChar
.String.replace(char, char)
String replace(String string, String match, String replace)
match
with the string replace
in the given
string.string
- is the string where to replace.match
- is the string that is searched and replaced.replace
- is the string match
is substituted with.match
replaced by replace
.String replaceSuffixWithCase(String string, int suffixLength, String newSuffixLowerCase)
replaceSuffixWithCase(String, int, String, Locale)
using Locale.ENGLISH
.string
- is the string to replace.suffixLength
- is the length of the suffix from string
to replace.newSuffixLowerCase
- is the new suffix for the given string
in lower-case
.string
with the last suffixLength
characters cut off and replaced by
newSuffixLowerCase
with respect to the original case of string
.replaceSuffixWithCase(String, int, String, Locale)
String replaceSuffixWithCase(String string, int suffixLength, String newSuffixLowerCase, Locale locale)
suffixLength
number of characters from string
with the lower-case
string newSuffixLowerCase
with respect to the original case of the given string
. Locale.ENGLISH
:string |
suffixLength |
newSuffixLowerCase |
replaceSuffixWithCase(String, int, String) |
---|---|---|---|
foobar | 3 | foo | foofoo |
FOOBAR | 3 | foo | FOOFOO |
FooBar | 3 | foo | FooFoo |
FooBar | 2 | foo | FooBfoo |
string
- is the string to replace.suffixLength
- is the length of the suffix from string
to replace.newSuffixLowerCase
- is the new suffix for the given string
in lower-case
.locale
- is the locale used for case transformation.string
with the last suffixLength
characters cut off and replaced by
newSuffixLowerCase
with respect to the original case of string
.boolean isEmpty(String string)
string
- is the string to check.true
if the given string is null
or has a trimmed length of zero, false
otherwise.isEmpty(String, boolean)
boolean isEmpty(String string, boolean trim)
string
- is the string to check.trim
- if whitespaces should be ignored and a string with a trimmed length of zero is considered as empty.true
if the given string is null
or has a (trimmed) length of zero, false
otherwise.boolean isAllUpperCase(String string)
string
are in upper case
.
string | isAllUpperCase (string) |
---|---|
UPPER_CASE | true |
lower_case | false |
CamlCase | false |
string
- the String
to check.true
if all characters are in upper case
, false
otherwise.boolean isAllLowerCase(String string)
string
are in lower case
.
string | isAllLowerCase (string) |
---|---|
UPPER_CASE | false |
lower_case | true |
CamlCase | false |
string
- the String
to check.true
if all characters are in lower case
, false
otherwise.String padNumber(long number, int digits)
padNumber(5, 3)
will return "005"
padNumber(25, 3)
will return "025"
padNumber(100, 3)
will return "100"
padNumber(1234, 3)
will return "1234"
number
- is the positive number to format.digits
- is the (minimum) number of digits required.digits
. If the number is less, leading zeros are
appended.String padNumber(long number, int digits, int radix)
radix
with at least the given number of
digits padding it with leading zeros. padNumber(31, 3, 16)
will return "01f"
padNumber(5, 6, 2)
will return "000101"
digits
: Radix | byte | short | int | long |
---|---|---|---|---|
2 | 8 | 16 | 32 | 64 |
8 | 3 | 6 | 9 | 12 |
10 | 3 | 5 | 9 | 19 |
16 | 2 | 4 | 8 | 16 |
number
- is the positive number to format.digits
- is the (minimum) number of digits required.radix
- is the radix to use.digits
. If the number is less, leading zeros are
appended.String toCamlCase(String string)
string
to caml-case syntax using the default separators ' '
,
'-'
, '_'
and '.'
.string
- is the string to convert.string
in caml-case syntax.toCamlCase(String, char[])
String toCamlCase(String string, char... separators)
string
to caml-case syntax. string
that are in the list given by separators
and
capitalizes the first character of the following word. string | toCamlCase(string) |
---|---|
foo bar |
fooBar |
aAa-bBB-CcC |
aAaBBBCcC |
X--m_._l.. |
XML |
string
- is the string to convert.separators
- is the list of characters that are treated as word-separators.string
in caml-case syntax.String fromCamlCase(String string, char separator)
string
from caml-case syntax to lower-case using the given separator
as word-boundary. string | separator | fromCamlCase (string, separator) |
---|---|---|
FooBar | - | foo-bar |
someWordMix | . | some.word.mix |
AbbreviationsLikeXMLshouldNotBeCapitalized | _ | abbreviations_like_xmlshould_not_be_capitalized |
FOO_BAR | * | foo_bar |
string
- is the string to convert.separator
- is the character to insert at word-boundaries indicated by a switch from lower- to upper-case.string
in lower-case with the given separator
inserted at word-boundaries.toCamlCase(String, char...)
boolean isSubstring(String string, String substring, int offset)
string
contains
the given
substring
at the given offset
. string.indexOf(substring, offset) == offsetor
string.substring(offset).beginsWith(substring)
string
- is the string potentially containing substring
.substring
- is the substring that should be contained in string
at the given offset
.offset
- is the offset in string
where to check for substring
.true
if the given string
contains
the given
substring
at the given offset
and false
otherwise.boolean isSubstring(char[] string, String substring, int offset)
string
contains
the given
substring
at the given offset
. string.indexOf(substring, offset) == offsetor
string.substring(offset).beginsWith(substring)
string
- is the char[] representing the string potentially containing substring
.substring
- is the substring that should be contained in string
at the given offset
.offset
- is the offset in string
where to check for substring
.true
if the given string
contains
the given
substring
at the given offset
and false
otherwise.String toSeparatedString(Collection<?> collection, String separator, StringSyntax syntax)
collection
to a string where each value is formatted to its
string representation
and separated by separator
. collection | separator | syntax.escape |
syntax.quoteStart |
syntax.quoteEnd |
toSeparatedString(Collection, String, StringSyntax) |
---|---|---|---|---|---|
{"abc;", "a,b,c", Integer.valueOf(123), Character.valueOf('\'') } |
"," |
'\\' |
'\0' |
'\0' |
"abc;,a\\,b\\,c,123,'" |
{"abc;", "a,b,c", Integer.valueOf(123), Character.valueOf('\'') } |
"," |
'\\' |
'\'' |
'\'' |
"'abc;','a,b,c','123','\\''" |
{"abc;", "a,b,c", Integer.valueOf(123), Character.valueOf('\'') } |
"; " |
'\\' |
'[' |
']' |
"[abc;]; [a,b,c]; [123]; [']" |
Collection
s with heterogeneous elements can NOT be converted back from String
.collection
- is the Collection
with the elements to format as separated string. May be
empty
.separator
- is the String
used to separate elements. It is appended after each but the last element.
Typically this should be a specific character that may be followed by a whitespace. Common separators are
comma (,) or semicolon (;) often also followed by a whitespace (", "
).syntax
- is the StringSyntax
defining escape
as well as
start
and end
of elements.<E> String toSeparatedString(Collection<E> collection, String separator, StringSyntax syntax, Formatter<E> formatter)
toSeparatedString(Collection, String, StringSyntax)
but allows to specify an explicit
Formatter
to use instead of Object.toString()
.E
- is the generic type of the elements in the collection.collection
- is the Collection
with the elements to format as separated string. May be
empty
.separator
- is the String
used to separate elements. It is appended after each but the last element.
Typically this should be a specific character that may be followed by a whitespace. Common separators are
comma (,) or semicolon (;) often also followed by a whitespace (", "
).syntax
- is the StringSyntax
defining escape
as well as
start
and end
of elements.formatter
- is the Formatter
to use.<E> void toSeparatedString(Collection<E> collection, String separator, StringSyntax syntax, Formatter<E> formatter, Appendable buffer)
toSeparatedString(Collection, String, StringSyntax)
but allows to specify an explicit
Formatter
to use instead of Object.toString()
.E
- is the generic type of the elements in the collection.collection
- is the Collection
with the elements to format as separated string. May be
empty
.separator
- is the String
used to separate elements. It is appended after each but the last element.
Typically this should be a specific character that may be followed by a whitespace. Common separators are
comma (,) or semicolon (;) often also followed by a whitespace (", "
).syntax
- is the StringSyntax
defining escape
as well as
start
and end
of elements.formatter
- is the Formatter
to use.buffer
- is where the separated string is appended
to.List<String> fromSeparatedString(CharSequence separatedString, String separator, StringSyntax syntax)
fromSeparatedString(CharSequence, String, StringSyntax, Collection, ValueConverter)
but expects elements of the type String
that do not need additional custom conversion.separatedString
- is the separated String
of elements to add to the collection.separator
- is the String
used to separate the individual elements in separatedString
. There
should be no separator
after the last element in separatedString
.syntax
- is the StringSyntax
defining escape
as well as
start
and end
of elements.List
of elements from separatedString
.void fromSeparatedString(CharSequence separatedString, String separator, StringSyntax syntax, Collection<String> collection)
fromSeparatedString(CharSequence, String, StringSyntax, Collection, ValueConverter)
but expects elements of the type String
that do not need additional custom conversion.separatedString
- is the separated String
of elements to add to the collection.separator
- is the String
used to separate the individual elements in separatedString
. There
should be no separator
after the last element in separatedString
.syntax
- is the StringSyntax
defining escape
as well as
start
and end
of elements.collection
- is where to add the elements to. This should be initially empty.<E> void fromSeparatedString(CharSequence separatedString, String separator, StringSyntax syntax, Collection<E> collection, ValueConverter<String,E> converter)
separatedString
that contains elements separated with separator
and
the given syntax
and adds
these elements to the given collection
.
toSeparatedString(Collection, String, StringSyntax, Formatter)
.E
- is the generic type of the elements in the collection.separatedString
- is the separated String
of elements to add to the collection.separator
- is the String
used to separate the individual elements in separatedString
. There
should be no separator
after the last element in separatedString
.syntax
- is the StringSyntax
defining escape
as well as
start
and end
of elements.collection
- is where to add the elements to. This should be initially empty.converter
- is used to parse the given elements from String
to their actual type ( <E>).<E> void fromSeparatedString(CharSequence separatedString, String separator, StringSyntax syntax, Collection<E> collection, ValueConverter<? super String,? super E> converter, Class<E> type)
separatedString
that contains elements separated with separator
and
the given syntax
and adds
these elements to the given collection
.
toSeparatedString(Collection, String, StringSyntax, Formatter)
.E
- is the generic type of the elements in the collection.separatedString
- is the separated String
of elements to add to the collection.separator
- is the String
used to separate the individual elements in separatedString
. There
should be no separator
after the last element in separatedString
.syntax
- is the StringSyntax
defining escape
as well as
start
and end
of elements.collection
- is where to add the elements to. This should be initially empty.converter
- is used to parse the given elements from String
to their actual type ( <E>).
May be the GenericValueConverter
.type
- is the Class
reflecting the elements to add to collection
.Copyright © 2001–2016 mmm-Team. All rights reserved.