|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfc.util.StringUtil
public final class StringUtil
Utility functions related to java.lang.String, i.e functions that are useful but not provided by that class.
| Constructor Summary | |
|---|---|
StringUtil()
|
|
| Method Summary | |
|---|---|
static String |
arrayToString(char[] array)
Converts a character array into a viewable comma delimited string. |
static String |
capitalWord(String str)
Converts the specified String to start with a capital letter. |
static String |
dirName(String str)
Returns the path component of the specified filename. |
static String |
escapeSingleQuotes(String str)
Escapes all single quotes in the specified a string with a backslash character. |
static String |
escapeSingleQuotes(String str,
String escape)
Escapes all single quotes in the specified a string with the specified escpape character. |
static String |
fileName(String str)
Returns the file component of specified filename. |
static String |
fixedWidth(String str,
int width)
Converts the specified String into a fixed width string, left padding (with a blank space) or truncating on the right as necessary. |
static String |
fixedWidth(String str,
int width,
HAlign align)
Calls fixedWidth(String, int, HAlign, char) specifying
the padding character as a blank space. |
static String |
fixedWidth(String str,
int width,
HAlign align,
char paddingChar)
Converts the specified String into a fixed width string. |
static String |
join(List list,
String delim)
Joins the elements of the specified list, delimited by the specified delimiter. |
static void |
main(String[] args)
|
static String |
nullToEmpty(Object val)
Returns an empty string is the specified argument was null, otherwise returns the value of the toString() method invoked on the specified object. |
static String |
nullToEmpty(String val)
Returns an empty string is the specified argument was null, otherwise returns the argument itself. |
static String |
remove(String target,
char[] chars)
Removes all occurences of specified characters from the specified string and returns the new resulting string. |
static String |
removeBeginningSlash(String str)
Removes the starting (at the very beginning of the string) forward or backward slash from the specified string (if any) and returns the resulting String. |
static String |
removeSuffix(String name)
Removes the any file extension (.foo for example) from the specified name and returns the resulting String. |
static String |
removeTrailingSlash(String str)
Removes the last forward or backward slash from the specified string (if any) and returns the resulting String. |
static String |
repeat(char c,
int length)
Returns a String containing a string of the specified character concatenated the specified number of times. |
static String |
repeat(String str,
int length)
Returns a String containing the specified string concatenated the specified number of times. |
static String |
repeatToWidth(String str,
int length)
Contatenates the given string so that the maximum length reached is the specified length. |
static String |
sentenceCase(String str,
String delimiters)
Converts the specified String to be in sentence case, whereby the first letter of each word in the sentence is uppercased and all other letters are lowercased. |
static List |
split(String str,
String delim)
Splits the string using the specified delimiters and returns the splits parts in a List. |
static String |
viewableAscii(char c)
A version of viewableAscii(String) that takes a
single char as a parameter. |
static String |
viewableAscii(String str)
Converts non printable ascii characters in the specified String to escaped or readable equivalents. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public StringUtil()
| Method Detail |
|---|
public static String nullToEmpty(String val)
public static String nullToEmpty(Object val)
public static String repeat(char c,
int length)
c - the character to be repeatedlength - the repeat length
public static String repeat(String str,
int length)
str - the string to be repeatedlength - the repeat length
public static String repeatToWidth(String str,
int length)
str - the string to repeatlength - the length of the returned string
public static String fixedWidth(String str,
int width)
str - the target stringwidth - the fixed width
public static String fixedWidth(String str,
int width,
HAlign align)
fixedWidth(String, int, HAlign, char) specifying
the padding character as a blank space.
public static String fixedWidth(String str,
int width,
HAlign align,
char paddingChar)
str - the target stringwidth - the fixed widthalign - the alignment of the target string within the widthpaddingChar - the character to pad the string (if necessary);
public static String remove(String target,
char[] chars)
target - the string to remove characters fromchars - an array of characters, each of which is to be removedpublic static String removeTrailingSlash(String str)
public static String removeBeginningSlash(String str)
public static String removeSuffix(String name)
name - the String denoting the file name to remove the extension frompublic static String dirName(String str)
The functionality of this method is different than java.io.File.getName() and getParent(). Also unix dirname, basename are also compared below. //Using java.io.File (getPath() returns the entire name, identical to //the input, so is not shown. Sample run on windows: Name='' ; getName()=''; getParent()='null' Name='/' ; getName()=''; getParent()='null' Name='/a' ; getName()='a'; getParent()='\' Name='a/b' ; getName()='b'; getParent()='a' Name='a/b.txt' ; getName()='b.txt'; getParent()='a' Name='b.txt' ; getName()='b.txt'; getParent()='null' Name='/a/' ; getName()='a'; getParent()='\' Name='/a/b/' ; getName()='b'; getParent()='\a' Name='a/b/' ; getName()='b'; getParent()='a' ---------------------------- //Using these methods: Name='' ; fileName()=''; dirName()='' Name='/' ; fileName()=''; dirName()='/' Name='/a' ; fileName()='a'; dirName()='/' Name='a/b' ; fileName()='b'; dirName()='a/' Name='a/b.txt' ; fileName()='b.txt'; dirName()='a/' Name='b.txt' ; fileName()='b.txt'; dirName()='' Name='/a/' ; fileName()=''; dirName()='/a/' Name='/a/b/' ; fileName()=''; dirName()='/a/b/' Name='a/b/' ; fileName()=''; dirName()='a/b/' ----------------------------- //unix basename, dirname Name='' ; basename()=''; dirname()='' Name='/' ; basename()='/'; dirname()='/' Name='/a' ; basename()='a'; dirname()='/' Name='a/b' ; basename()='b'; dirname()='a/' Name='a/b.txt' ; basename()='b.txt'; dirname()='a/' Name='b.txt' ; basename()='b.txt'; dirname()='.' Name='/a/' ; basename()='a'; dirname()='/' Name='a/b/' ; basename()='b'; dirname()='a' Name='/a/b/' ; fileName()='b'; dirName()='a' -----------------------------Note, the main differences among the 3 approaches above are in the last 2 statements in each section.
public static String fileName(String str)
public static List split(String str,
String delim)
String.split(java.lang.String, int) instead for greater options.
str - the string to be tokenizeddelim - delimiter string, each character in the string will be used
as a delimiter to use while tokenizing
public static String join(List list,
String delim)
list - containing the elements to be joined.delim - delimits each element from the nextpublic static String capitalWord(String str)
public static String sentenceCase(String str,
String delimiters)
public static String viewableAscii(String str)
If the specified String is null, this method returns null.
str - the String to convert
public static String viewableAscii(char c)
viewableAscii(String) that takes a
single char as a parameter.
char - the char to convert
public static String arrayToString(char[] array)
public static String escapeSingleQuotes(String str)
public static String escapeSingleQuotes(String str,
String escape)
public static void main(String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||