Modifier and Type | Class and Description |
---|---|
static interface |
StringUtils.ParameterProvider
Provides
String parameter values for the format method. |
Modifier and Type | Field and Description |
---|---|
static String |
LINEFEED
line feed constant used in StringUtils.
|
static String |
NEWLINE
newline constant used in StringUtils.
|
static String |
TAB
tab constant used in StringUtils.
|
Modifier and Type | Method and Description |
---|---|
static String |
charAt(String str,
int index)
Gets the character at
index as new String. |
static String |
concat(String separator,
Collection<?> values)
Returns a
String representation of all elements of the provided
Collection values separated by the specified
separator . |
static String |
concat(String separator,
Object... values)
Returns a
String representation of all elements of the provided
values separated by the specified separator . |
static boolean |
contains(String str,
String search)
|
static String |
create(String source,
int count)
|
static XdevList<String> |
explode(String str,
String separator)
|
static XdevList<String> |
explode(String str,
String separator,
boolean returnDelimiters)
|
static String |
format(String str,
Map<String,String> params)
|
static String |
format(String str,
StringUtils.ParameterProvider parameterProvider)
|
static int |
getUnicodeNr(char ch)
Returns the unicode number for the prodvied
ch . |
static int |
getUnicodeNr(String str)
Returns the unicode number for the prodvied
String
str . |
static String |
getUnicodeString(int number)
Returns the unicode character for the provided number.
|
static String |
implode(Collection<?> list,
String separator)
Deprecated.
replaced by
concat(String, Collection) |
static String |
replaceAll(String source,
String search,
String replacement)
|
static String |
substr(String str,
int start,
int length)
Returns a new string that is a substring of
str . |
public static final String NEWLINE
public static final String LINEFEED
public static final String TAB
public static String charAt(String str, int index) throws NullPointerException, IndexOutOfBoundsException
index
as new String.
Examples:
StringUtils.charAt("XDEV", 0) returns "X" StringUtils.charAt("Bar", 2) returns "r" StringUtils.charAt("Hello XDEV3", 6) returns "X"
str
- the String to get the character from.index
- the position of the character. 0 <= index
<
length of str
. The first character has
index
0.str
. The
first char
value is at index 0
.NullPointerException
- if str
is null
IndexOutOfBoundsException
- if the index
argument is negative or not less
than the length of str
.public static boolean contains(String str, String search) throws NullPointerException
true
if and only if String
str
contains the specified String
search
. This method is
case sensitive.
Examples:
StringUtils.contains("Hello XDEV3", "beta") returns false StringUtils.contains("Hello XDEV3", "Xdev3") returns false StringUtils.contains("Hello XDEV3", "XDEV3") returns true
str
- the String
to search insearch
- the String
to search fortrue
if String
str
contains
search
, false otherwiseNullPointerException
- if str
is null
NullPointerException
- if search
is null
public static String substr(String str, int start, int length) throws NullPointerException, IndexOutOfBoundsException
str
. The
substring begins with the character at the specified index
start
and contains the following number of characters
specified by length
.
Examples:
StringUtils.substr("New York",4,4) returns "York" StringUtils.substr("New York",0,3) returns "New"
str
- the String
to operate onstart
- the beginning index, inclusive.length
- the length of the substringNullPointerException
- if str
is null
IndexOutOfBoundsException
- if start
is negative or greater than the length
of str
. If length
is negative or
greater than the length of str
-
start
.public static String replaceAll(String source, String search, String replacement) throws NullPointerException
String
source
that matches the given String
search
with the given
String
replacement
.
Hint: The String
source
remains
unchanged. All operations take place on a newly created String that is
returned by this method.
Examples:
StringUtils.replaceAll("This is a String","is","at") returns "That at a String" StringUtils.replaceAll("In Betatest","In","For") returns "For Betatest"
source
- String
to search insearch
- String
to search forreplacement
- String
to replace the String
search
withNullPointerException
- if source
, search
or
replacement
are null
.public static XdevList<String> explode(String str, String separator)
String
str
at every separator
String
separator
.
Examples:
XdevList<String> expected = new XdevList<String>(); expected.add("Hello"); expected.add("XDEV3"); XdevList<String> actual = StringUtils.explode("Hello,XDEV3",","); Assert.assertEquals(expected,actual);
This method is a alias for
StringUtils.explode(str, separator, false)
str
- the String
to be splitseparator
- the separatorXdevList
containing all parts of the given String
str
split at every separator String
separator
.explode(String, String, boolean)
public static XdevList<String> explode(String str, String separator, boolean returnDelimiters) throws NullPointerException
String
str
at every separator
String
separator
.
Examples:
StringUtils.explode("XDEV IDE based on java", " ", true) returns a list with 9 elements StringUtils.explode("XDEV IDE based on java", " ", false) returns a list with 5 elements XdevListexpected = new XdevList (); expected.add("Hello"); expected.add("world"); expected.add("and"); expected.add("space"); XdevList actual = StringUtils.explode("Hello,world,and,space", ",",false);
str
- the String
to be splitseparator
- the separatorreturnDelimiters
- if true
the separator is returned as independent
element in the list; otherwise it is not.XdevList
containing all parts of the given String
str
split at every separator String
separator
.NullPointerException
- if eighter str
or separator
is
null
explode(String, String)
,
concat(String, Collection)
,
concat(String, Object...)
@Deprecated public static String implode(Collection<?> list, String separator) throws NullPointerException
concat(String, Collection)
NullPointerException
public static String create(String source, int count) throws NullPointerException, IllegalArgumentException
String
with the value of n (provided
count
) times the provided String
str
.
Examples:
StringUtils.create("Hello!",3); returns "Hello!Hello!Hello!" StringUtils.create("XDEV!",2); returns "XDEV!XDEV!" StringUtils.create("XDEV!XDEV2!XDEV3",1); returns "XDEV!XDEV2!XDEV3" *
source
- String
to use as source for the new String
count
- how many times should the provided String
be repeated.
Count
is valid for >= 0.String
with the value of n (provided
count
) times the provided String
str
.NullPointerException
- if source
is null
IllegalArgumentException
- if count
is not valid (<0)public static String getUnicodeString(int number)
Examples:
StringUtils.getUnicodeString(65) returns "A" StringUtils.getUnicodeString(75) returns "K"
number
- of the unicode characterpublic static int getUnicodeNr(String str) throws IllegalArgumentException
String
str
.
Examples:
StringUtils.getUnicodeNr("A") returns 65 StringUtils.getUnicodeNr("H") returns 72
str
- String
to get the unicode number for. Str
must have length = 1.String
str
.IllegalArgumentException
- if String
has length != 1public static int getUnicodeNr(char ch)
ch
.
Examples:
StringUtils.getUnicodeNr('A') returns 65 StringUtils.getUnicodeNr('F') returns 70
ch
- to get the unicode number for.ch
.public static String concat(String separator, Collection<?> values) throws NullPointerException
String
representation of all elements of the provided
Collection
values
separated by the specified
separator
.
Examples:
StringUtils.concat(", ", new XdevList<String>("Miami","Atalanta","Vegas","LA")); returns "Miami, Atalanta, Vegas, LA" StringUtils.concat("-", new XdevList("Rom","Munich","Berlin","Madrid")) returns "Rom-Munich-Berlin-Madrid"
separator
- String to separated the list elements.values
- the Collection
to concatString
representation of all elements of the provided
Collection
values
separated by the specified
separator
.NullPointerException
- if values
or separator
is
null
concat(String, Object...)
,
explode(String, String)
,
explode(String, String, boolean)
public static String concat(String separator, Object... values) throws NullPointerException
String
representation of all elements of the provided
values
separated by the specified separator
.
Examples:
StringUtils.concat(", ", new XdevList<String>("Miami","Atalanta","Vegas","LA")); returns "Miami, Atalanta, Vegas, LA" StringUtils.concat(".", new XdevList("Wien","Graz","Frankfurt","Dublin")); returns "Wien.Graz.Frankfurt.Dublin"
separator
- String to separated the list elements.values
- the values to concatString
representation of all elements of the provided
values
separated by the specified
separator
.NullPointerException
- if values
or separator
is
null
concat(String, Collection)
,
explode(String, String)
,
explode(String, String, boolean)
public static String format(String str, Map<String,String> params)
String
str
by replacing the variables
with values provided by params
.
For more information see format(String, ParameterProvider)
public static String format(String str, StringUtils.ParameterProvider parameterProvider)
String
str
by replacing the variables
with values provided by parameterProvider
.
Variables have the format {$variableName}
.
Given: parameter provider (name -> Peter, color -> blue) Result of format("{$name} loves the color {$color}.",provider) is "Peter loves the color blue".
str
- the String
to formatparameterProvider
- the StringUtils.ParameterProvider
String
Copyright © 2003–2021 XDEV Software. All rights reserved.