public class StringUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
EOL |
static String |
NEWLINE |
| Modifier and Type | Method and Description |
|---|---|
static String |
cat(String separator,
String... list)
Concatenate a list of strings, putting a separator in between each one.
|
static String |
escapeForHtml(String str)
Escape characters to use result in html.
|
static String |
formatSQLException(SQLException ex)
Returns a String containing SQLState, message and error code of exception and all sub-exceptions
|
static String |
getPenultimateDirName(String s)
e.g.
|
static String |
getProperty(String propName)
Get a system propety given a property name, possibly trying all combination
of upercase, name mangling to get a value.
|
static String |
getStackTrace(Throwable t)
Gets a String version of the stack trace of an exception
|
static boolean |
isHex(char c)
Is this the char a valid hex digit?
|
static boolean |
isHex(String s)
Is this the String representation of a valid hex number?
"5", "d", "D", "F454ecbb" all return true..
|
static boolean |
isToken(String s)
Returns true is the given string is of the form "${text}"
|
static void |
main(String[] args) |
static String |
makeFilePath(String[] strings,
boolean addTrailing)
A utility to get the Operating System specific path from given array
of Strings.
|
static int |
maxWidth(Vector v)
Find longest String in a vector of Strings...
|
static String |
nvl(String str)
If given
String is null then returns empty String
otherwise returns given String |
static boolean |
ok(String s)
Returns true if a string is not null and has a non-zero length, false otherwise
|
static String |
padLeft(String s,
int len)
Adds spaces to the front of a string to make it reach the specified length.
|
static String |
padRight(String s,
int len)
Adds spaces to the end of a string to make it reach the specified length.
|
static List<String> |
parseStringList(String line)
Parses a string containing substrings separated from
each other by the standard separator characters and returns
a list of strings.
|
static List<String> |
parseStringList(String line,
String sep)
Parses a string containing substrings separated from
each other by the specified set of separator characters and returns
a list of strings.
|
static void |
prepend(String[] ss,
String what)
Puts a string before every element in an array
|
static String |
quotePathIfNecessary(String path)
Nightmares can result from using a path with a space in it!
This method will enclose in double-quotes if needed.
|
static String |
quotePathIfNecessary(String path,
char quoteChar)
Nightmares can result from using a path with a space in it!
This method will enclose in the specified quote characters if needed.
|
static String |
removeChar(String strOrig,
char c)
Remove a character from a String
|
static String |
removeEnclosingQuotes(String s)
Removes the quoting around a String.
|
static String |
replace(String s,
String token,
String replace)
Deprecated.
Now part of
String since JDK 1.5 |
static int |
safeLength(String s)
return the length of the String - or 0 if it's null
|
static String |
stripToken(String s)
Removes preceding
${ and trailing } from a String |
static void |
testUpperCase() |
static String[] |
toLines(String s)
Converts a String into an array where every \n is a new used to signal a new element in the array
|
static String |
toShortClassName(String className)
Returns the classname without package info
|
static String |
toString(Properties props)
Converts a
Properties object to string |
static String |
upperCaseFirstLetter(String s)
Converts the first letter of a string to upper case
|
public static int safeLength(String s)
s - public static boolean ok(String s)
s - public static String formatSQLException(SQLException ex)
ex - public static int maxWidth(Vector v)
v - public static boolean isHex(String s)
s. - public static boolean isHex(char c)
Can be upper or lower case
c - public static String getPenultimateDirName(String s)
s - public static String toShortClassName(String className)
i.e. java.lang.String would return String
className - The classname to convert. Note that there is no checking that this is a valid classname.public static String padRight(String s, int len)
If the string is longer than the padded length then this function will return the original string.
s - String to padlen - The length of the string with added paddingpublic static String padLeft(String s, int len)
If the string is longer than the padded length then this function will return the original string.
s - String to padlen - The length of the string with added paddingpublic static String[] toLines(String s)
s - public static void prepend(String[] ss, String what)
i.e. prepend(new String["foo", "bar"],"not ") would result in String["not foo", "not bar"]
ss - what - public static String upperCaseFirstLetter(String s)
s - public static String replace(String s, String token, String replace)
String since JDK 1.5s - The string to operate ontoken - the token to be replacedreplace - the new valueString.replace(CharSequence, CharSequence),
String.replaceFirst(String, String)public static String toString(Properties props)
Properties object to string
If there it is empty then this will return "No entries". Otherwise it will be in the form of "key= value" with each property on a new line.
props - public static void main(String[] args)
public static void testUpperCase()
public static String makeFilePath(String[] strings, boolean addTrailing)
strings - an array of Strings participating in the path.addTrailing - a boolean that determines whether the returned
String should have a trailing File Separator character. None of
the strings may be null or empty String. An exception is thrown.IllegalArgumentException - if any of the arguments is null or is
an empty string.public static List<String> parseStringList(String line)
line into individual string elements
separated by the field separators, and returns these individual
strings as a list of strings. The individual string elements are
trimmed of leading and trailing whitespace. Only non-empty strings
are returned in the list.line - The string to splitpublic static List<String> parseStringList(String line, String sep)
line into individual string elements
separated by the field separators specified in sep,
and returns these individual strings as a list of strings. The
individual string elements are trimmed of leading and trailing
whitespace. Only non-empty strings are returned in the list.line - The string to splitsep - The list of separators to use for determining where the
string should be split. If null, then the standard
separators (see StringTokenizer javadocs) are used.public static String getProperty(String propName)
propName - the approximate system property namepublic static String removeChar(String strOrig, char c)
strOrig - original stringc - character to remove from the stringpublic static String getStackTrace(Throwable t)
t - public static final boolean isToken(String s)
s - public static final String stripToken(String s)
${ and trailing } from a Strings - public static String cat(String separator, String... list)
separator - Separator to use between concatenated stringslist - List of strings to concatenate togetherpublic static String removeEnclosingQuotes(String s)
s - The String that may have enclosing quotespublic static String quotePathIfNecessary(String path)
path - public static String quotePathIfNecessary(String path, char quoteChar)
path - quoteChar - public static String escapeForHtml(String str)
| Chars | Escape sequence |
|---|---|
| < | < |
| > | > |
| & | & |
| " | " |
| \t |
str - Copyright © 2017. All rights reserved.