|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mindprod.common11.StringTools
public class StringTools
Miscellaneous static methods for dealing with Strings in JDK 1.1+.
Augmented by com.mindprod.common15.StringTools for JDK 1.5+.
Constructor Summary | |
---|---|
protected |
StringTools()
Dummy constructor StringTools contains only static methods. |
Method Summary | |
---|---|
static void |
beep()
makeshift system beep if awt.Toolkit.beep is not available. |
static java.lang.String |
canonical(java.lang.String s)
Convert String to canonical standard form. |
static java.lang.String |
chopLeadingString(java.lang.String text,
java.lang.String toChop)
remove leading string if present |
static java.lang.String |
chopTrailingString(java.lang.String text,
java.lang.String toChop)
remove trailing string if present |
static java.lang.String |
condense(java.lang.String s)
Collapse multiple spaces in string down to a single space. |
static int |
countInstances(java.lang.String page,
char lookFor)
Count how many times a char occurs in a String. |
static int |
countInstances(java.lang.String page,
java.lang.String lookFor)
Count how many times a String occurs on a page. |
static int |
countLeading(java.lang.String text,
char c)
count of how many leading characters there are on a string matching a given character. |
static int |
countLeading(java.lang.String text,
java.lang.String possibleChars)
count of how many leading characters there are on a string matching a given character. |
static int |
countTrailing(java.lang.String text,
char c)
count of how many trailing characters there are on a string matching a given character. |
static int |
countTrailing(java.lang.String text,
java.lang.String possibleChars)
count of how many trailing characters there are on a string matching a given character. |
static java.lang.String |
firstWord(java.lang.String s)
gets the first word of a String, delimited by space or the end of the string. |
static boolean |
haveCommonChar(java.lang.String a,
java.lang.String b)
Returns true if strings a and b have one or more characters in common, not necessarily at the same offset. |
static int |
indexOfWhiteSpace(java.lang.String s)
find the first instance of whitespace (space, \n, \r, \t in a string. |
static int |
indexOfWhiteSpace(java.lang.String s,
int startOffset)
find the first instance of whitespace (space, \n, \r, \t in a string. |
static boolean |
isDigit(char c)
Check if char is plain ASCII digit. |
static boolean |
isEmpty(java.lang.String s)
Is this string empty? In Java 1.6 + isEmpty is build in. |
static boolean |
isLegal(char candidate,
java.lang.String legalChars)
Ensure the char is only one a set of legal characters. |
static boolean |
isLegal(java.lang.String candidate,
java.lang.String legalChars)
Ensure the string contains only legal characters. |
static boolean |
isLetter(char c)
Check if char is plain ASCII letter lower or upper case. |
static boolean |
isUnaccentedLowerCase(char c)
Check if char is plain ASCII lower case. |
static boolean |
isUnaccentedUpperCase(char c)
Check if char is plain ASCII upper case. |
static boolean |
isVowel(char c)
is this character a vowel? |
static java.lang.String |
lastWord(java.lang.String s)
gets the last word of a String, delimited by space or the end of the string. |
static java.lang.String |
leftJustified(int value,
int newLen,
boolean chop)
Pads the string value out to the given length by applying blanks on the right, left justifying the value. |
static java.lang.String |
leftPad(java.lang.String s,
int newLen,
boolean chop)
Pads the string out to the given length by applying blanks on the left. |
static void |
main(java.lang.String[] args)
Test harness, used in debugging |
static long |
parseDirtyLong(java.lang.String numStr)
convert a String to a long. |
static long |
parseLongPennies(java.lang.String numStr)
convert a String into long pennies. |
static java.lang.String |
penniesToString(long pennies)
Print dollar currency, stored internally as scaled int. |
static int |
pluck(java.lang.String s)
Extracts a number from a string, returns 0 if malformed. |
static java.lang.String[] |
pruneExcessBlankLines(java.lang.String[] lines,
int minBlankLinesToKeep)
Collapse multiple blank lines down to one. |
static java.lang.String |
quoteSQL(java.lang.String sql)
used to prepare SQL string literals by doubling each embedded ' and wrapping in ' at each end. |
static java.lang.String |
rep(char c,
int count)
Produce a String of a given repeating character. |
static java.lang.String |
rightJustified(int value,
int newLen,
boolean chop)
Pads the string value out to the given length by applying blanks on the left, right justifying the value. |
static java.lang.String |
rightPad(java.lang.String s,
int newLen,
boolean chop)
Pads the string out to the given length by applying blanks on the right. |
static java.lang.String |
spaces(int n)
Generate a string of spaces n chars long. |
static java.lang.String |
squish(java.lang.String s)
Remove all spaces from a String. |
static java.lang.String |
toBookTitleCase(java.lang.String s)
convert to Book Title case, with first letter of each word capitalised. |
static java.lang.String |
toHexString(int h)
Convert int to hex with lead zeroes |
static char |
toLowerCase(char c)
Quick replacement for Character.toLowerCase for use with English-only. |
static java.lang.String |
toLowerCase(java.lang.String s)
Quick replacement for Character.toLowerCase for use with English-only. |
static java.lang.String |
toLZ(int i,
int len)
Convert an integer to a String, with left zeroes. |
static java.lang.String |
toLZHexString(int value,
int len)
convert an integer value to unsigned hex with leading zeroes. |
static java.lang.String |
toString(java.awt.Color c)
Get #ffffff html hex number for a colour |
static char |
toUpperCase(char c)
Quick replacement for Character.toUpperCase for use with English-only. |
static java.lang.String |
toUpperCase(java.lang.String s)
Quick replacement for Character.toUpperCase for use with English-only. |
static java.lang.String |
trimLeading(java.lang.String s)
Removes white space from beginning this string. |
static java.lang.String |
trimLeading(java.lang.String text,
char c)
trim leading characters there are on a string matching a given character. |
static java.lang.String |
trimLeading(java.lang.String text,
java.lang.String toTrim)
trim leading characters there are on a string matching a given characters |
static java.lang.String |
trimTrailing(java.lang.String s)
Removes white space from end this string. |
static java.lang.String |
trimTrailing(java.lang.String text,
char c)
trim trailing characters there are on a string matching a given character. |
static java.lang.String |
trimTrailing(java.lang.String text,
java.lang.String toTrim)
trim trailing characters there are on a string matching given characters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected StringTools()
Method Detail |
---|
public static void beep()
public static java.lang.String canonical(java.lang.String s)
s
- String to be converted.
public static java.lang.String chopLeadingString(java.lang.String text, java.lang.String toChop)
text
- text with possible leading string, possibly empty or null.toChop
- the leading string of interest. Not a list of possible chars to chop, order matters.
trimLeading(String,String)
,
chopTrailingString(String,String)
public static java.lang.String chopTrailingString(java.lang.String text, java.lang.String toChop)
text
- text with possible trailing string, possibly empty, but not null.toChop
- the trailing string of interest. Not a list of possible chars to chop, order matters.
trimTrailing(String,String)
,
chopLeadingString(String,String)
public static java.lang.String condense(java.lang.String s)
s
- String to strip of blanks.
squish(String)
public static int countInstances(java.lang.String page, java.lang.String lookFor)
page
- big String to look in.lookFor
- small String to look for and count instances.
public static int countInstances(java.lang.String page, char lookFor)
page
- big String to look in.lookFor
- char to lookfor count instances.
public static int countLeading(java.lang.String text, char c)
text
- text with possible leading characters, possibly empty, but not null.c
- the leading character of interest, usually ' ' or '\n'
public static int countLeading(java.lang.String text, java.lang.String possibleChars)
text
- text with possible leading characters, possibly empty, but not null.possibleChars
- the leading characters of interest, usually ' ' or '\n'
public static int countTrailing(java.lang.String text, char c)
text
- text with possible trailing characters, possibly empty, but not null.c
- the trailing character of interest, usually ' ' or '\n'
public static int countTrailing(java.lang.String text, java.lang.String possibleChars)
text
- text with possible trailing characters, possibly empty, but not null.possibleChars
- the trailing characters of interest, usually ' ' or '\n'
public static java.lang.String firstWord(java.lang.String s)
s
- the input String
lastWord(String)
public static boolean haveCommonChar(java.lang.String a, java.lang.String b)
a
- first stringb
- second string
public static int indexOfWhiteSpace(java.lang.String s)
s
- string to scan
public static int indexOfWhiteSpace(java.lang.String s, int startOffset)
s
- string to scanstartOffset
- where in string to start looking
public static boolean isDigit(char c)
c
- char to check.
Character.isLetter(char)
public static boolean isEmpty(java.lang.String s)
s
- String to be tested for emptiness.
public static boolean isLegal(java.lang.String candidate, java.lang.String legalChars)
candidate
- string to test.legalChars
- characters than are legal for candidate.
public static boolean isLegal(char candidate, java.lang.String legalChars)
candidate
- char to test.legalChars
- characters than are legal for candidate.
public static boolean isLetter(char c)
c
- char to check.
Character.isLowerCase(char)
,
Character.isUpperCase(char)
,
Character.isDigit(char)
public static boolean isUnaccentedLowerCase(char c)
c
- char to check.
Character.isLowerCase(char)
,
Character.isLetter(char)
public static boolean isUnaccentedUpperCase(char c)
c
- char to check.
Character.isUpperCase(char)
,
Character.isLetter(char)
public static boolean isVowel(char c)
c
- the character, any char upper or lower case, punctuation or symbol
public static java.lang.String lastWord(java.lang.String s)
s
- the input String
firstWord(String)
public static java.lang.String leftJustified(int value, int newLen, boolean chop)
value
- value to be converted to string String to be padded/chopped.newLen
- length of new String desired.chop
- true if Strings longer than newLen should be truncated to newLen chars.
toLZ(int, int)
public static java.lang.String leftPad(java.lang.String s, int newLen, boolean chop)
s
- String to be padded/chopped.newLen
- length of new String desired.chop
- true if Strings longer than newLen should be truncated to newLen chars.
toLZ(int, int)
public static long parseDirtyLong(java.lang.String numStr)
numStr
- String to be parsed.
java.lang.NumberFormatException
- if the number is too big to fit in a long.public static long parseLongPennies(java.lang.String numStr)
numStr
- String to be parsed.
java.lang.NumberFormatException
- if the number is too big to fit in a long.public static java.lang.String penniesToString(long pennies)
pennies
- long amount in pennies.
public static int pluck(java.lang.String s)
s
- String containing the integer.
public static java.lang.String[] pruneExcessBlankLines(java.lang.String[] lines, int minBlankLinesToKeep)
lines
- array of lines to tidy.minBlankLinesToKeep
- usually 1 meaning 1+ consecutive blank lines become 1, effectively collapsing
runs of blank lines down to 1.
if 2, 1 blank line is removed, and 2+ consecutive blanks lines become 1,
effectively undouble spacing.
if zero, non-blank lines will be separated by one blank line, even if there was not
one there to begin with, completely independent of preexisting blank lines,
effectively double spacing..
9999 effectively removes all blank lines.
public static java.lang.String quoteSQL(java.lang.String sql)
sql
- Raw SQL string literal
public static java.lang.String rep(char c, int count)
c
- the character to repeatcount
- the number of times to repeat
public static java.lang.String rightJustified(int value, int newLen, boolean chop)
value
- value to be converted to string String to be padded/chopped.newLen
- length of new String desired.chop
- true if Strings longer than newLen should be truncated to newLen chars.
toLZ(int, int)
public static java.lang.String rightPad(java.lang.String s, int newLen, boolean chop)
s
- String to be padded/chopped.newLen
- length of new String desired.chop
- true if Strings longer than newLen should be truncated to newLen chars.
public static java.lang.String spaces(int n)
n
- how many spaces long
public static java.lang.String squish(java.lang.String s)
s
- String to strip of blanks.
condense(String)
public static java.lang.String toBookTitleCase(java.lang.String s)
s
- String to convert. May be any mixture of case.
public static java.lang.String toHexString(int h)
h
- number you want to convert to hex
toString(Color)
public static java.lang.String toLZ(int i, int len)
i
- the integer to be convertedlen
- the length of the resulting string. Warning. It will chop the result on the left if it is too long.
leftPad(java.lang.String, int, boolean)
public static java.lang.String toLZHexString(int value, int len)
value
- integer to convert.len
- how many characters you want in the result.
public static char toLowerCase(char c)
c
- character to convert
public static java.lang.String toLowerCase(java.lang.String s)
s
- String to convert
public static java.lang.String toString(java.awt.Color c)
c
- Color object whose html colour number you want as a string
toHexString(int)
public static char toUpperCase(char c)
c
- character to convert
public static java.lang.String toUpperCase(java.lang.String s)
s
- String to convert
public static java.lang.String trimLeading(java.lang.String s)
s
- String to process. As always the original in unchanged.
All characters that have codes less than or equal to '\u0020'
(the space character) are
considered to be white space.
public static java.lang.String trimLeading(java.lang.String text, char c)
text
- text with possible trailing characters, possibly empty, but not null.c
- the trailing character of interest, usually ' ' or '\n'
trimLeading(String)
public static java.lang.String trimLeading(java.lang.String text, java.lang.String toTrim)
text
- text with possible trailing characters, possibly empty, but not null.toTrim
- the leading characters of interest, usually ' ' or '\n'
trimTrailing(String)
,
chopLeadingString(String,String)
public static java.lang.String trimTrailing(java.lang.String s)
s
- String to process. As always the original in unchanged.
All characters that have codes less than or equal to '\u0020'
(the space character) are
considered to be white space.
public static java.lang.String trimTrailing(java.lang.String text, char c)
text
- text with possible trailing characters, possibly empty, but not null.c
- the trailing character of interest, usually ' ' or '\n'
trimTrailing(String)
public static java.lang.String trimTrailing(java.lang.String text, java.lang.String toTrim)
text
- text with possible trailing characters, possibly empty, but not null.toTrim
- the trailing characters of interest, usually ' ' or '\n'
trimTrailing(String)
,
chopTrailingString(String,String)
public static void main(java.lang.String[] args)
args
- not used
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |