public class StringTool extends Object implements Serializable
| Constructor and Description |
|---|
StringTool() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
AllInRange(int x,
int y,
String theString) |
static String |
allTrim(String holder)
Lose the whitespace at the end of strings...
|
static String |
arrayToString(Object[] objs)
convert an Array to a String representation of its objects
|
static String |
convertDatePatternFromExcelToStringFormatter(String pattern) |
static String |
convertDBtoJavaStyleConvention(String name)
converts underscored DB-style naming convention to java member naming
convention
|
static String |
convertFilenameToJSPName(String name)
converts underscored DB-style naming convention to java member naming
convention
|
static String |
convertHTML(String rep)
replace endoded text with normal text ie: "&" is converted to "&"
check out the w3 list of XML
characters
|
static String |
convertJavaStyletoDBConvention(String name)
converts java member naming convention to underscored DB-style naming
convention
ie: take upperCamelCase and turn into upper_camel_case
|
static String |
convertJavaStyletoFriendlyConvention(String name)
converts java member naming convention to underscored DB-style naming
convention
ie: take upperCamelCase and turn into upper_camel_case
|
static String |
convertPatternExtractBracketedExpression(String pattern)
extract info, if any, from bracketed expressions within Excel custom number formats
|
static String |
convertPatternFromExcelToStringFormatter(String pattern,
boolean isNegative)
converts an excel-style custom format to String.format custom format i.e.
|
static String |
convertXMLChars(String rep)
replace illegal XML characters with their html counterparts
ie: "&" is converted to "&"
check out the w3 list of XML
characters
|
static String |
dbencode(String holder) |
static double |
getApproximateCharWidth(Font f,
Character c)
return the approximate witdth in width in pixels of the given character
|
static double |
getApproximateHeight(Font f,
String s,
double w)
return the approximate height it takes to display the given string in the
given font in the given width
|
static double |
getApproximateStringWidth(Font f,
String s)
given a string, return the maximum of the width in pixels in the given
the awt Font.
|
static double |
getApproximateStringWidthLB(Font f,
String s)
given a string, return the maximum of the width in pixels in the given
the awt Font Observing Line Breaks.
|
static String |
getCompressedUnicode(byte[] input)
get compressed UNICODE string from uncompressed string
|
static String |
getGetMethodNameFromVar(String thismember)
generate a "getXXXX" string from a field name per Extentech java naming
conventions.
|
static String |
getLowerCaseFirstLetter(String thismember) |
static String |
getPath(String filePath)
strips the path portion from a filepath and returns it
|
static String |
getSetMethodNameFromVar(String thismember)
generate a "setXXXX" string from a field name per Extentech java naming
conventions.
|
static String |
getTextBetweenDelims(String originalText,
String beginDelim,
String endDelim)
This method will retrieve the first instance of text between any two
given patterns.
|
static String |
getTextBetweenNestedDelims(String originalText,
String beginDelim,
String endDelim)
This method will retrieve the first instance of text between any two
given patterns.
|
static String[] |
getTokensUsingDelim(String instr,
String token)
Basically a String tokenizer
|
static String |
getUpperCaseFirstLetter(String thismember) |
static String |
getVarNameFromGetMethod(String thismethod)
get the variable name for a "getXXXX" a field name per JavaBean java
naming conventions.
|
static void |
main(String[] args) |
static String |
makeDelimitedList(Object[] list,
String delimiter)
Each object in the array must support the .toString() method, as it will
be used to render the object to its string representation.
|
static String |
proper(String name)
converts strings to "proper" capitalization
ie: take "mr.
|
static String |
qualifyFilePath(String fPath)
returns file path fPath qualified with an ending slash
|
static String |
qualifyPatternString(String pattern)
qualifies a pattern string to make valid for applying the pattern
|
static String |
readString(Reader reader)
Reads from a
Reader into a String. |
static String |
replaceChars(String theFilter,
String theString,
String replacement) |
static String |
replaceExtension(String filepath,
String ext)
replaces the extension of a filepath with an new extension
|
static String |
replaceSection(String originalText,
String replaceBegin,
String replacementText,
String replaceEnd)
This method will replace any instance of given text within another
string.
|
static String |
replaceText(String theString,
String theFilter,
String replacement)
replace a section of text based on pattern match throughout string.
|
static String |
replaceText(String originalText,
String replaceText,
String replacementText,
int offset)
Replaces an occurence of String B with String C within String A.
|
static String |
replaceText(String originalText,
String replaceText,
String replacementText,
int offset,
boolean skipmatch)
Replaces an occurence of String B with String C within String A.
|
static String |
replaceTokenFromArray(String replace,
String token,
String[] vals)
Replaces a specified token in a string with a value from the passed
through array this is done in matching order from String to Arrray.
|
static String |
rTrim(String originalText)
Trims whitespace from the right side of strings.
|
static String[] |
splitFilepath(String filePath)
splits a filepath into directory and filename
|
static String[] |
splitString(String value,
String delimeter)
Returns an array of strings from a single string, similar to
String.split() in JavaScript
|
static String |
stackTraceToString(Throwable target)
Returns the given throwable's stack trace as a string.
|
static String |
strip(String tostrip,
char stripchar)
Strips all occurences of a character from a given string.
|
static String |
strip(String tostrip,
String stripstr)
Strips all occurences of a string from a given string.
|
static String |
StripChars(String theFilter,
String theString) |
static String |
stripHTML(String rep)
strip out all most HTML tags
|
static String |
stripMatch(String pattern,
String matchstr)
If the string matches any part of the pattern, strip the pattern from the
string.
|
static String |
stripPath(String filePath)
strips the path portion from a filepath and returns the filename
|
static String |
stripTrailingSpaces(String s)
strip trailing spaces
|
static String |
UseOnlyChars(String theFilter,
String theString) |
public static String convertXMLChars(String rep)
rep - public static void main(String[] args)
public static String stripHTML(String rep)
rep - public static String convertHTML(String rep)
rep - public static String stripMatch(String pattern, String matchstr)
public static String getVarNameFromGetMethod(String thismethod)
public static String convertJavaStyletoDBConvention(String name)
public static String convertJavaStyletoFriendlyConvention(String name)
public static String arrayToString(Object[] objs)
name - public static final String stackTraceToString(Throwable target)
target - the Throwable whose stack trace should be returnedNullPointerException - if target is nullpublic static String proper(String name)
public static String makeDelimitedList(Object[] list, String delimiter)
public static String[] splitString(String value, String delimeter)
public static String getCompressedUnicode(byte[] input)
public static String getSetMethodNameFromVar(String thismember)
public static String getGetMethodNameFromVar(String thismember)
public static String convertDBtoJavaStyleConvention(String name)
public static String convertFilenameToJSPName(String name)
public static String[] getTokensUsingDelim(String instr, String token)
instr - token - public static String allTrim(String holder)
holder - The String that you want stripped.public static String strip(String tostrip, String stripstr)
tostrip - The String that you want stripped.stripchar - The char you want stripped from the String.public static String strip(String tostrip, char stripchar)
tostrip - The String that you want stripped.stripchar - The char you want stripped from the String.public static String replaceText(String originalText, String replaceText, String replacementText, int offset, boolean skipmatch)
originalText - Original textreplaceText - Text to replace.replacementText - Text to replace with.offset - offset of replacement within original string.public static String replaceText(String originalText, String replaceText, String replacementText, int offset)
originalText - Original textreplaceText - Text to replace.replacementText - Text to replace with.offset - offset of replacement within original string.public static String rTrim(String originalText)
originalText - Text to trim.public static String getTextBetweenNestedDelims(String originalText, String beginDelim, String endDelim)
originalText - Text to process.beginDelim - Delimeter for beginning of retrieved section.endDelim - Delimeter for end of retrieved section.public static String getTextBetweenDelims(String originalText, String beginDelim, String endDelim)
originalText - Text to process.beginDelim - Delimeter for beginning of retrieved section.endDelim - Delimeter for end of retrieved section.public static String replaceSection(String originalText, String replaceBegin, String replacementText, String replaceEnd)
originalText - Text to process.replaceBegin - Beggining pattern of replaced section.replacementText - Text to replace with.replaceEnd - End pattern of replaced section.public static String replaceChars(String theFilter, String theString, String replacement)
public static String replaceText(String theString, String theFilter, String replacement)
public static boolean AllInRange(int x,
int y,
String theString)
public static String replaceTokenFromArray(String replace, String token, String[] vals)
public static String qualifyFilePath(String fPath)
fPath - public static String[] splitFilepath(String filePath)
filePath - public static String stripPath(String filePath)
filePath - public static String getPath(String filePath)
filePath - public static String replaceExtension(String filepath, String ext)
filepath - Source FilePahtext - public static double getApproximateStringWidth(Font f, String s)
f - awt Fonts - String to computepublic static double getApproximateStringWidthLB(Font f, String s)
f - awt Fonts - String to computepublic static double getApproximateCharWidth(Font f, Character c)
f - awt Fontc - characterpublic static double getApproximateHeight(Font f, String s, double w)
f - java.awt.Fonts - Stringw - width in pointspublic static String convertPatternFromExcelToStringFormatter(String pattern, boolean isNegative)
NOTE: the pattern should be a single item in the excel-style format i.e.one of the terms in positive;negative;zero;text
without semicolon.
NOTE: the java-specific pattern returned will have the negative formatting (sign, parenthesis ...) and so, when used,
the double value must be it's absolute value i.e String.format(pattern, Math.abs(d))
NOTE: date formats are handled separately. this only applies to number and currency formats
Excel-style:
0 (zero) Digit placeholder. This code pads the value with zeros to fill the format.
# Digit placeholder. This code does not display extra zeros.
? Digit placeholder. This code leaves a space for insignificant zeros but does not display them.
. (period) Decimal number.
% Percentage. Microsoft Excel multiplies by 100 and adds the % character.
, (comma) Thousands separator. A comma followed by a placeholder scales the number by a thousand.
E+ E- e+ e- Scientific notation.
Text Code Description
$ - + / ( ) : space These characters are displayed in the number. To display any other character, enclose the character in quotation marks or precede it with a backslash.
\character This code displays the character you specify.
"text" This code displays text.
This code repeats the next character in the format to fill the column width. Note Only one asterisk per section of a format is allowed.
_ (underscore) This code skips the width of the next character.
This code is commonly used as "_)" (without the quotation marks)
to leave space for a closing parenthesis in a positive number format
when the negative number format includes parentheses.
This allows the values to line up at the decimal point.
pattern - String format pattern in Excel formatisNegative - true if the source is a negative numberpublic static String convertDatePatternFromExcelToStringFormatter(String pattern)
public static String convertPatternExtractBracketedExpression(String pattern)
pattern - String Excel number formatpublic static String qualifyPatternString(String pattern)
pattern - public static String readString(Reader reader) throws IOException
Reader into a String.
Blocking reads will be issued to the reader and the results will be
concatenated into a string, which will be returned once the reader
reports end-of-input.reader - the Reader from which to readIOExceptionCopyright © 2002–2019 Starter Inc.. All rights reserved.