public class StringExt
extends java.lang.Object
Str| Constructor and Description |
|---|
StringExt() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Character |
charAt(java.lang.String str,
int index)
Returns the character at the given index, or null if
index is out of range. |
static java.lang.String |
chomp(java.lang.String str)
Removes a single end of line character, either \\n or \\r.
|
static java.lang.String |
chompAll(java.lang.String str)
Removes multiple end of line characters, either \\n or \\r.
|
static boolean |
contains(java.lang.String str,
java.lang.Character ch)
Returns whether the string contains the character.
|
static java.lang.Boolean |
eq(java.lang.String a,
java.lang.String b)
Returns whether the two strings are equal.
|
static java.lang.Boolean |
eqi(java.lang.String a,
java.lang.String b)
Returns whether the two strings are equal, without regard to case.
|
static java.lang.Character |
get(java.lang.String str,
int index)
An alias for StringExt#charAt.
|
static java.lang.String |
get(java.lang.String str,
java.lang.Integer fromIndex,
java.lang.Integer toIndex)
Same as StringExt#substring, but with the indices inclusive, like the Ruby syntax
str[4
.. |
static java.lang.Integer |
indexOf(java.lang.String str,
java.lang.Character ch)
Returns the index of the first occurance of the character in the string, or null if either
str or ch is null, or if the character is not in the string. |
static boolean |
isEmpty(java.lang.String str)
Returns whether the string is null or of zero length.
|
static java.lang.String |
join(java.util.Collection<?> coll,
java.lang.String delim)
Returns the collection, joined by
delim. |
static java.lang.String |
join(java.lang.Object[] ary,
java.lang.String str)
Returns the array, joined by
str. |
static java.lang.String |
left(java.lang.String str,
int num)
Returns the leftmost
num characters of the string, not exceeding the length of
the string. |
static int |
length(java.lang.String str)
Returns the length of the string, returning 0 if the string is null.
|
static java.lang.String |
pad(java.lang.String str,
char ch,
int length)
Returns a string starting with the
str parameter, with ch's
following the string to a length of length. |
static java.lang.String |
pad(java.lang.String str,
int length)
Pads with trailing spaces.
|
static java.lang.String |
padLeft(java.lang.String str,
char ch,
int length)
Same as the
pad method, but applies the padding to the left-hand (leading) side
of the string. |
static java.lang.String |
padLeft(java.lang.String str,
int length)
Left-pads with spaces.
|
static java.lang.String |
quote(java.lang.String str)
Quotes the string, using double quotes.
|
static java.lang.String |
repeat(char ch,
int length)
Returns the character, repeated
num times. |
static java.lang.String |
repeat(java.lang.String str,
int num)
Returns the string, repeated
num times. |
static java.lang.String |
right(java.lang.String str,
int num)
Returns the rightmost
num characters of the string, not exceeding the length of
the string. |
static java.lang.String |
snip(java.lang.String str,
int len)
If
str is longer than length, then the returned string is cut at
the given length and appended with a dash, so snip("foobar", 3) is "foo-. |
static java.lang.String[] |
split(java.lang.String str,
char delim)
Returns an array of strings split at the character delimiter.
|
static java.lang.String[] |
split(java.lang.String str,
char delim,
int max)
Returns an array of strings split at the character delimiter.
|
static java.lang.String[] |
split(java.lang.String str,
java.lang.String delim)
Returns an array of strings split at the string delimiter.
|
static java.lang.String[] |
split(java.lang.String str,
java.lang.String delim,
int max)
Returns an array of strings split at the string delimiter.
|
static boolean |
startsWith(java.lang.String str,
char ch)
Returns whether the string
str begins with the character ch. |
static boolean |
startsWith(java.lang.String str,
java.lang.String pref)
Returns whether the string
str begins with the string prefix. |
static java.lang.String |
substring(java.lang.String str,
java.lang.Integer fromIndex,
java.lang.Integer toIndex)
Returns a substring from the string, with negatives indices applying to the distance from the
end of the string.
|
static java.lang.String |
substringAfter(java.lang.String str,
java.lang.Character ch)
Returns the substring from the
ch character to the end of the string. |
static java.lang.String |
substringBefore(java.lang.String str,
java.lang.Character ch)
Returns the substring before the
ch character. |
static java.util.List<java.lang.String> |
toList(java.lang.String str)
Converts the (possibly quoted) string into a list, delimited by whitespace and commas.
|
static java.lang.String |
unquote(java.lang.String str)
Unquotes the string, removing matching leading and trailing single or double quotes, if both
of either type wraps the string.
|
public static java.lang.String[] split(java.lang.String str,
char delim,
int max)
str is null.public static java.lang.String[] split(java.lang.String str,
java.lang.String delim,
int max)
str
is null.public static java.lang.String[] split(java.lang.String str,
char delim)
str is null.public static java.lang.String[] split(java.lang.String str,
java.lang.String delim)
str
is null.public static java.util.List<java.lang.String> toList(java.lang.String str)
str is null.
The unquoting behavior exists for pre-3.0 versions of IJDK.Str.unquote(),
Str.toList()public static java.lang.String pad(java.lang.String str,
char ch,
int length)
str parameter, with ch's
following the string to a length of length.
Examples:
pad("abcd", '*', 8) -> "abcd****"
pad("abcd", '*', 3) -> "abcd"
public static java.lang.String padLeft(java.lang.String str,
char ch,
int length)
pad method, but applies the padding to the left-hand (leading) side
of the string.
Examples:
pad("420", '*', 8) -> "*****420"
pad("1144", '*', 3) -> "1144"
public static java.lang.String pad(java.lang.String str,
int length)
public static java.lang.String padLeft(java.lang.String str,
int length)
public static java.lang.String repeat(java.lang.String str,
int num)
num times.public static java.lang.String repeat(char ch,
int length)
num times.public static java.lang.String left(java.lang.String str,
int num)
num characters of the string, not exceeding the length of
the string. Does not throw the annoying IndexOutOfBoundsException. Returns null if the input
string is null. Returns an empty string if num is negative.public static java.lang.String right(java.lang.String str,
int num)
num characters of the string, not exceeding the length of
the string. Does not throw the annoying IndexOutOfBoundsException. Returns null if the input
string is null. Returns an empty string if num is negative.public static java.lang.String join(java.util.Collection<?> coll,
java.lang.String delim)
delim. Returns null if coll is
null. If delim is null, it is treated as the empty string.public static java.lang.String join(java.lang.Object[] ary,
java.lang.String str)
str. Returns null if ary is null. If
str is null, it is treated as the empty string.public static java.lang.Character charAt(java.lang.String str,
int index)
index is out of range. If
index is negative, the character is the nth character from the end of the
string, where -1 is the last character in the string.str - The source string.index - The index into the source string. Negative value goes from end backward.public static java.lang.Character get(java.lang.String str,
int index)
charAt(String, int)public static java.lang.String substring(java.lang.String str,
java.lang.Integer fromIndex,
java.lang.Integer toIndex)
fromIndex is null, the substring begins with the first
character. If toIndex is null, the substring ends with the last character. If
the indices are out of bounds, they will be restricted to the size of the string. The range
is inclusive: "foobar"[2 .. 4] == "oba", which is unlike the JDK
String#substring behavior, where the equivalent would be str.substring(2, 5).
If str is null, then null is returned.get(String, Integer, Integer)public static java.lang.String substringAfter(java.lang.String str,
java.lang.Character ch)
ch character to the end of the string. If the
string does not contain the given character, or if str or ch is
null, then null is returned. If ch is the last character, then an empty string
is returned.public static java.lang.String substringBefore(java.lang.String str,
java.lang.Character ch)
ch character. If the string does not contain
the given character, , or if str or ch is null, then null is
returned. If ch is the first character, then an empty string is returned.public static java.lang.String get(java.lang.String str,
java.lang.Integer fromIndex,
java.lang.Integer toIndex)
str[4
.. 8]. This method the same as StringExt.substring.public static boolean startsWith(java.lang.String str,
char ch)
str begins with the character ch.
Returns false if str is null.public static boolean startsWith(java.lang.String str,
java.lang.String pref)
str begins with the string prefix. For
consistency with String. Returns false if str is null.public static java.lang.String chomp(java.lang.String str)
chompAll(java.lang.String)public static java.lang.String chompAll(java.lang.String str)
public static boolean contains(java.lang.String str,
java.lang.Character ch)
str or ch is
null, false is returned.public static java.lang.Integer indexOf(java.lang.String str,
java.lang.Character ch)
str or ch is null, or if the character is not in the string.public static java.lang.Boolean eq(java.lang.String a,
java.lang.String b)
public static java.lang.Boolean eqi(java.lang.String a,
java.lang.String b)
public static java.lang.String snip(java.lang.String str,
int len)
str is longer than length, then the returned string is cut at
the given length and appended with a dash, so snip("foobar", 3) is "foo-.
Returns null if str is null. Returns an empty string if length is
zero or less.public static boolean isEmpty(java.lang.String str)
public static int length(java.lang.String str)
public static java.lang.String unquote(java.lang.String str)
public static java.lang.String quote(java.lang.String str)