|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bristle.javalib.util.StrUtil
public class StrUtil
This class contains utility routines for manipulating Java Strings.
Usage: - Typical scenarios for using this class are: - 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); - See the source code of the inner Tester class for more examples. Assumptions: Effects: - None. Anticipated Changes: Notes: Implementation Notes: Portability Issues: Revision History: $Log$
Nested Class Summary | |
---|---|
static class |
StrUtil.Tester
Each class contains a Tester inner class with a main() for easier unit testing. |
Constructor Summary | |
---|---|
StrUtil()
|
Method Summary | |
---|---|
static boolean |
containsAnyChar(String strString,
String strChars)
Return true if strString contains any of the chars in strChars; false otherwise. |
static boolean |
containsAnyOtherChar(String strString,
String strChars)
Return true if strString contains any char other than those in strChars; false otherwise. |
static boolean |
equalsIgnoreCaseOrBothNull(String str1,
String str2)
Return true if the specified Strings are equal or both null; false otherwise. |
static boolean |
equalsIgnoreCaseOrBothNullOrEmpty(String str1,
String str2)
Return true if the specified Strings are equalsIgnoreCase() or if both of them are null or empty; false otherwise. |
static boolean |
equalsOrBothNullOrEmpty(String str1,
String str2)
Return true if the specified Strings are equal or if both of them are null or empty; false otherwise. |
static String |
insertAfterDelimiters(String strString,
char chDelim,
String strInsert)
Return a string that is a copy of strString with strInsert inserted after each occurrence of chDelim. |
static String |
insertCommas(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 boolean |
isNullOrEmpty(String strIn)
Return true if the specified String is null or empty; false otherwise. |
static String |
left(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 String |
lpad(String strString,
char chPad,
int intLength)
Left pad a string. |
static String |
ltrim(String strString,
String strMatch)
Left trim a string. |
static String |
makeStringOfChars(char chChar,
int intLength)
Return a string containing intLength occurrences of the character chChar. |
static String |
mapEmptyToNull(String strIn)
Returns null if the specified string, when trimmed, is null or empty. |
static String |
quoteDelimitedSubstrings(String strString,
char chDelim,
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 String |
replaceAll(String strIn,
String strFrom,
String strTo)
Return a String that is a copy of strIn with all occurrences of strFrom replaced with strTo. |
static String |
replaceFirst(String strIn,
String strFrom,
String strTo)
Return a String that is a copy of strIn with the first occurrences, if any, of strFrom replaced with strTo. |
static String |
right(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 String |
rpad(String strString,
char chPad,
int intLength)
Right pad a string. |
static String |
rtrim(String strString,
String strMatch)
Right trim a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StrUtil()
Method Detail |
---|
public static boolean isNullOrEmpty(String strIn)
strIn
- String to compare.
public static boolean equalsOrBothNullOrEmpty(String str1, String str2)
str1
- String to compare.str2
- String to compare.
public static boolean equalsIgnoreCaseOrBothNullOrEmpty(String str1, String str2)
str1
- String to compare.str2
- String to compare.
public static boolean equalsIgnoreCaseOrBothNull(String str1, String str2)
str1
- String to compare.str2
- String to compare.
public static String mapEmptyToNull(String strIn)
strIn
- The input string.
public static String replaceAll(String strIn, String strFrom, String strTo)
strIn
- String to start with.strFrom
- String to change from.strTo
- String to change to.
public static String replaceFirst(String strIn, String strFrom, String strTo)
strIn
- String to start with.strFrom
- String to change from.strTo
- String to change to.
public static String quoteDelimitedSubstrings(String strString, char chDelim, String strQuote)
strString
- String to search for delimited substrings.chDelim
- Delimiter character.strQuote
- String to insert before and after each substring.
public static String insertAfterDelimiters(String strString, char chDelim, String strInsert)
strString
- String to search for delimited substrings.chDelim
- Delimiter character.strInsert
- String to insert after each delimiter.
public static String makeStringOfChars(char chChar, int intLength)
chChar
- Character to put in the string.intLength
- Desired length of the result string.
public static String lpad(String strString, char chPad, int intLength)
strString
- String to pad.chPad
- Character to pad with.intLength
- Desired length of the result string.
public static String rpad(String strString, char chPad, int intLength)
strString
- String to pad.chPad
- Character to pad with.intLength
- Desired length of the result string.
public static String ltrim(String strString, String strMatch)
strString
- String to trim.strMatch
- Substring to remove.
public static String rtrim(String strString, String strMatch)
strString
- String to trim.strMatch
- Substring to remove.
public static String left(String strString, int intLength)
strString
- String to get substring from.intLength
- Max length of the substring to return. Negative
values rounded up to zero.
public static String right(String strString, int intLength)
strString
- String to get substring from.intLength
- Max length of the substring to return. Negative
values rounded up to zero.
public static String insertCommas(String strString)
strString
- String to insert commas into.
public static boolean containsAnyChar(String strString, String strChars)
strString
- String to search.strChars
- String of chars to search for.
public static boolean containsAnyOtherChar(String strString, String strChars)
strString
- String to search.strChars
- String of chars to search for.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |