public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_TAB_WIDTH |
static String |
TAB_STRING |
Modifier and Type | Method and Description |
---|---|
static boolean |
equalsIgnoreWhitespace(String s1,
String s2) |
static boolean |
equalsIgnoreWhitespace(String s1,
String s2,
boolean ignoreCase) |
static String |
escape(String s) |
static String |
fitToBox(String value,
int width,
int height) |
static String |
fitToBox(String value,
int width,
int height,
boolean html) |
static String |
fitToHeight(String value,
int height) |
static String |
fitToWidth(String value,
int width) |
static String |
formatDoubleLikeCpp(double value)
Tries to format double the C++ iostream way, with up to 6 digits shown after the decimal point.
|
static int |
getHeight(String value) |
static int |
getWidth(String value) |
static String |
htmlDecode(String value) |
static String |
htmlDecode(String value,
boolean replaceSpecialChars) |
static String |
htmlEncode(boolean value) |
static String |
htmlEncode(char value) |
static String |
htmlEncode(double value) |
static String |
htmlEncode(int value) |
static String |
htmlEncode(long value) |
static String |
htmlEncode(Object value) |
static String |
htmlEncode(String value) |
static String |
htmlEncode(String value,
boolean replaceSpecialChars) |
static String |
htmlEncode(String value,
boolean replaceSpecialChars,
boolean nbsp) |
static boolean |
isFalsey(String value) |
static boolean |
isTruthy(String value) |
static String |
join(Iterable<String> tokens,
String delimiter) |
static String |
join(String[] tokens,
String delimiter) |
static String |
join(String[] tokens,
String delimiter,
int limit) |
static String |
join(String[] tokens,
String delimiter,
int startIndex,
int limit) |
static int |
levenshtein(String s1,
String s2)
Returns the Levenshtein edit distance between the two given strings;
the number of characters that must be added, removed, or modified to
turn the one string into the other.
|
static String |
nCopies(String s,
int n)
Returns a string that contains s repeated n times.
|
static String |
numberLines(String s) |
static String |
padL(int s,
int width) |
static String |
padL(String s,
int width) |
static String |
padNumber(int n,
int length) |
static String |
padNumber(int n,
int length,
boolean html) |
static String |
padR(int s,
int width) |
static String |
padR(String s,
int width) |
static boolean[] |
parseBooleanArray(String s) |
static char[] |
parseCharArray(String s) |
static double[] |
parseDoubleArray(String s) |
static int[] |
parseIntArray(String s) |
static int[][] |
parseIntArray2D(String s) |
static Point |
parsePoint(String value) |
static String[] |
parseStringArray(String s) |
static String |
plural(int n) |
static String |
removeWhitespace(String s) |
static String |
sortChars(String s) |
static boolean |
stringIsBoolean(String text) |
static boolean |
stringIsDouble(String text) |
static boolean |
stringIsInteger(String text) |
static boolean |
stringIsInteger(String text,
int radix) |
static boolean |
stringIsReal(String text) |
static String |
toAsciiDump(String s) |
static String |
toPrintableChar(char c) |
static String |
toString(Point p) |
static String |
trimBlankLines(String s)
Removes any blank lines (just \n or spaces/tabs followed by \n) from the
start/end of s.
|
static String |
trimEnd(String s) |
static String |
trimEndsOfLines(String s) |
static String |
trimLines(String s)
Trims out any leading/trailing whitespace from all lines of string s.
|
static String |
trimR(String s) |
static String |
truncate(String s,
int length)
Trims the given string to be at most the given number of characters in length.
|
static String |
truncate(String s,
int length,
String suffix)
Trims the given string to be at most the given number of characters in length.
|
static String |
unindent(String s)
Looks at all lines of the given string, figuring out how 'indented' each
line is; then removes the longest common indentation prefix string that
occurs in all lines.
|
static String |
untabify(String s)
Replaces tabs with a string of spaces of a default width.
|
static String |
untabify(String s,
int tabWidth)
Replaces tabs with a string of spaces of the given width.
|
static String |
urlDecode(String s) |
static String |
urlEncode(String s) |
static String |
wrapLines(String s,
int length) |
public static final int DEFAULT_TAB_WIDTH
public static final String TAB_STRING
public static String formatDoubleLikeCpp(double value)
public static int getWidth(String value)
public static int getHeight(String value)
public static String htmlEncode(int value)
public static String htmlEncode(double value)
public static String htmlEncode(char value)
public static String htmlEncode(boolean value)
public static String htmlEncode(long value)
public static boolean isFalsey(String value)
public static boolean isTruthy(String value)
public static int levenshtein(String s1, String s2)
http://en.wikipedia.org/wiki/Levenshtein_distance
public static String nCopies(String s, int n)
s
- string to repeat. if s is null, returns null.n
- number of repetitions. if <= 0, returns "".public static String padL(int s, int width)
public static String padR(int s, int width)
public static String padNumber(int n, int length)
public static String padNumber(int n, int length, boolean html)
public static boolean[] parseBooleanArray(String s)
public static char[] parseCharArray(String s)
public static double[] parseDoubleArray(String s)
public static int[] parseIntArray(String s)
public static int[][] parseIntArray2D(String s)
public static String plural(int n)
public static boolean equalsIgnoreWhitespace(String s1, String s2, boolean ignoreCase)
public static boolean stringIsBoolean(String text)
public static boolean stringIsDouble(String text)
public static boolean stringIsInteger(String text)
public static boolean stringIsInteger(String text, int radix)
public static boolean stringIsReal(String text)
public static String toPrintableChar(char c)
public static String trimBlankLines(String s)
public static String trimLines(String s)
public static String truncate(String s, int length)
public static String truncate(String s, int length, String suffix)
public static String unindent(String s)
public static String untabify(String s)
public static String untabify(String s, int tabWidth)