public final class StringUtils extends Object
Emphasis on performance and reduced memory allocation/garbage collection in exchange for longer more complex code.
Modifier and Type | Method and Description |
---|---|
static String |
dequote(String str,
char quote)
Undoubles the quotes inside the string
Example: |
static String |
dequote(String str,
int begin,
int end,
char quote)
Undoubles the quotes inside a substring
Example: |
static String |
dequoteFull(String str,
char quote)
Removes the surrounding quote and any double quote inside the string
Example: |
static String |
dequoteFull(String str,
int begin,
int end,
char quote) |
static boolean |
isFloatNoExponent(String str)
Checks that the string represents a floating point number that CANNOT be
in exponential notation
|
static boolean |
isFloatWithOptionalExponent(String str) |
static boolean |
isInteger(String str) |
static boolean |
isUnsignedInteger(String str) |
static int |
minIndex(int a,
int b)
Returns the minimum index >= 0, if any
|
static StringBuffer |
replace(StringBuffer out,
String s,
String repl,
String with) |
static StringBuilder |
replace(StringBuilder out,
String s,
String repl,
String with) |
static String |
replace(String str,
char repl,
String with) |
static String |
replace(String str,
String repl,
String with) |
static String[] |
splitLongString(String str,
char separator)
Split a string into an array of strings arround a character separator.
|
static String[] |
splitLongString(String str,
char separator,
char quote)
Split a string into an array of strings arround a character separator.
|
static String[] |
splitShortString(String str,
char separator)
Split a string into an array of strings arround a character separator.
|
static String[] |
splitShortString(String str,
char separator,
char quote)
Split a string into an array of strings arround a character separator.
|
static String |
substring(String str,
int begin,
int end) |
static String[] |
trim(String[] strings) |
public static boolean isFloatNoExponent(String str)
str
- the string to checkpublic static boolean isFloatWithOptionalExponent(String str)
public static boolean isInteger(String str)
public static boolean isUnsignedInteger(String str)
public static String dequote(String str, char quote)
hello""world becomes hello"world
str
- input string to dequotequote
- the quoting charpublic static String dequote(String str, int begin, int end, char quote)
hello""world becomes hello"worldWARNING: scan for quote may continue to the end of the string, make sure that either
charAt(end + 1) == quote
or end =
str.lentgth()
. If in doubt call
dequote(str.substring(begin, end), quote)
str
- input string from which to get the substring, must not be
nullbegin
- begin index for substringend
- end index for substringquote
- the quoting charIllegalArgumentException
- if string is incorrectly quotedpublic static String dequoteFull(String str, char quote)
"hello""world" becomes hello"world
str
- input string to dequotequote
- the quoting charpublic static StringBuffer replace(StringBuffer out, String s, String repl, String with)
public static StringBuilder replace(StringBuilder out, String s, String repl, String with)
public static String[] splitLongString(String str, char separator)
str
- the string to be splitseparator
- the separator characterpublic static String[] splitLongString(String str, char separator, char quote)
str
- the string to be splitseparator
- the separator characterquote
- the quote characterIllegalArgumentException
- DOCUMENT ME!public static String[] splitShortString(String str, char separator)
str
- the string to be splitseparator
- the separator characterpublic static String[] splitShortString(String str, char separator, char quote)
str
- the string to be splitseparator
- the separator characterquote
- the quote characterIllegalArgumentException
- DOCUMENT ME!public static int minIndex(int a, int b)
Use to find the first of two characters in a string:
minIndex(s.indexOf('/'), indexOf('\'))
a
- b
- Copyright © 2020 The Apache Software Foundation. All rights reserved.