Package edu.indiana.lib.twinpeaks.util
Class StringUtils
- java.lang.Object
-
- edu.indiana.lib.twinpeaks.util.StringUtils
-
public class StringUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringcapitalize(String text)Capitlize each word in a string (journal titles, etc)static booleanisNull(String string)Null (or zero-length) String?static voidmain(String[] args)static StringremoveCharacterOrRangeAsCharacter(String source, String pattern)Remove a character (or range of characters) from a string.static StringremoveCharacterOrRangeAsWord(String source, String pattern)Remove a character (or range of characters) from a string.static Stringreplace(String text, String targetText, String newText)Replace all occurances of the target text with the provided replacement text.static StringtrimAll(String text, char character)Trim specified charcater from both ends of a Stringstatic StringtrimEnd(String text, char character)Trim specified charcater from end of stringstatic StringtrimFront(String text, char character)Trim specified charcater from front of stringstatic StringtruncateAtWhitespace(String text, int length)Truncate text on a whitespace boundary (near a specified length).
-
-
-
Method Detail
-
replace
public static String replace(String text, String targetText, String newText)
Replace all occurances of the target text with the provided replacement text. Both target and replacement may be regular expressions - seejava.util.regex.Matcher.- Parameters:
text- Text to modifytargetText- Text to find and replacenewText- New text- Returns:
- Updated text
-
isNull
public static boolean isNull(String string)
Null (or zero-length) String?
-
truncateAtWhitespace
public static String truncateAtWhitespace(String text, int length)
Truncate text on a whitespace boundary (near a specified length). The length of the resultant string will be in the range:
(requested-length * .25) ~ (requested-length * 1.5)- Parameters:
text- Text to truncatelength- Target length- Returns:
- Truncated text
-
trimFront
public static String trimFront(String text, char character)
Trim specified charcater from front of string- Parameters:
text- Textcharacter- Character to remove- Returns:
- Trimmed text
-
trimEnd
public static String trimEnd(String text, char character)
Trim specified charcater from end of string- Parameters:
text- Textcharacter- Character to remove- Returns:
- Trimmed text
-
trimAll
public static String trimAll(String text, char character)
Trim specified charcater from both ends of a String- Parameters:
text- Textcharacter- Character to remove- Returns:
- Trimmed text
-
capitalize
public static String capitalize(String text)
Capitlize each word in a string (journal titles, etc)- Parameters:
text- Text to inspect- Returns:
- Capitalized text
-
removeCharacterOrRangeAsWord
public static String removeCharacterOrRangeAsWord(String source, String pattern)
Remove a character (or range of characters) from a string. If the character is in a word, remove the entire word.- Parameters:
source- String to editpattern- Character (or range) to remove. Range is a regular expression:[,-/]or[,-/]- Returns:
- Modified text
-
removeCharacterOrRangeAsCharacter
public static String removeCharacterOrRangeAsCharacter(String source, String pattern)
Remove a character (or range of characters) from a string. If the character is at the start or end of a word, remove the character only (leave the word in place).- Parameters:
source- String to editpattern- Character (or range) to remove. Range is a regular expression:[,-/]or[,-/]- Returns:
- Modified text
-
-