|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--StrUtil
This class contains utility routines for manipulating Java Strings.
Usage: - The typical scenario for using this class is: - Put quotes around comma-separated substrings. String strOut = StrUtil.quoteDelimitedSubstrings(strIn, ',', "'"); - Put spaces after commas. String strOut = StrUtil.insertAfterDelimiters(strIn, ',', " "); - Create a string of 5 stars (*): String strOut = StrUtil.makeStringOfChars('*', 5); - Pad string on left with zeros to a total length of 10 chars. String strOut = StrUtil.lpad(strIn, '0', 10); - Pad string on right with blanks to a total length of 7 chars. String strOut = StrUtil.rpad(strIn, ' ', 7); - Get the leftmost 7 chars: String strOut = StrUtil.left(strIn, 7); - Get the rightmost 7 chars: String strOut = StrUtil.right(strIn, 7); Assumptions: Effects: - None. Anticipated Changes: Notes: Implementation Notes: Portability Issues:
Inner Class Summary | |
static class |
StrUtil.Tester
Each class contains a Tester inner class with a main() for easier unit testing. |
Constructor Summary | |
StrUtil()
Constructor. |
Method Summary | |
static java.lang.String |
insertAfterDelimiters(java.lang.String strString,
char chDelim,
java.lang.String strInsert)
Return a string that is a copy of strString with strInsert inserted after each occurrence of chDelim. |
static java.lang.String |
insertCommas(java.lang.String strString)
Returns the specified string with commas inserted every 3 chars counting from the right -- the traditional formatting of a large number, broken into ones, thousands, millions, etc. |
static java.lang.String |
left(java.lang.String strString,
int intLength)
Returns a string containing the specified number of chars copied from the beginning of a string, or less if the specified string is too short. |
static java.lang.String |
lpad(java.lang.String strString,
char chPad,
int intLength)
Left pad a string. |
static java.lang.String |
makeStringOfChars(char chChar,
int intLength)
Return a string containing intLength occurrences of the character chChar. |
static java.lang.String |
quoteDelimitedSubstrings(java.lang.String strString,
char chDelim,
java.lang.String strQuote)
Return a string that is a copy of strString with strQuote inserted before and after each substring that is delimited by chDelim. |
static java.lang.String |
replaceAll(java.lang.String strIn,
java.lang.String strFrom,
java.lang.String strTo)
Return a String that is a copy of strIn with all occurrences of strFrom replaced with strTo. |
static java.lang.String |
right(java.lang.String strString,
int intLength)
Returns a string containing the specified number of chars copied from the end of a string, or less if the specified string is too short. |
static java.lang.String |
rpad(java.lang.String strString,
char chPad,
int intLength)
Right pad a string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StrUtil()
None.
- Exceptions
- None.Method Detail |
public static java.lang.String replaceAll(java.lang.String strIn, java.lang.String strFrom, java.lang.String strTo)
strIn
- String to start with.strFrom
- String to change from.strTo
- String to change to.Exceptions
- None.public static java.lang.String quoteDelimitedSubstrings(java.lang.String strString, char chDelim, java.lang.String strQuote)
strString
- String to search for delimited substrings.chDelim
- Delimiter character.strQuote
- String to insert before and after each substring.Exceptions
- None.public static java.lang.String insertAfterDelimiters(java.lang.String strString, char chDelim, java.lang.String strInsert)
strString
- String to search for delimited substrings.chDelim
- Delimiter character.strInsert
- String to insert after each delimiter.Exceptions
- None.public static java.lang.String makeStringOfChars(char chChar, int intLength)
chChar
- Character to put in the string.intLength
- Desired length of the result string.Exceptions
- None.public static java.lang.String lpad(java.lang.String strString, char chPad, int intLength)
strString
- String to pad.chPad
- Character to pad with.intLength
- Desired length of the result string.Exceptions
- None.public static java.lang.String rpad(java.lang.String strString, char chPad, int intLength)
strString
- String to pad.chPad
- Character to pad with.intLength
- Desired length of the result string.Exceptions
- None.public static java.lang.String left(java.lang.String strString, int intLength)
strString
- String to get substring from.intLength
- Max length of the substring to return. Negative
values rounded up to zero.Exceptions
- None.public static java.lang.String right(java.lang.String strString, int intLength)
strString
- String to get substring from.intLength
- Max length of the substring to return. Negative
values rounded up to zero.Exceptions
- None.public static java.lang.String insertCommas(java.lang.String strString)
strString
- String to insert commas into.Exceptions
- None.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |