|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lava.string.StringToolbox
Miscellaneous string utilities.
Details: StringToolbox
is a miscellaneous collection of functions for manipulating strings. Functions in this class are place here because they do not fit neatly into the function spaces represented by the other classes in this package.
Changes:
looksLikeAnEmailAddress (String)
.
NumberString
,
PathToolbox
,
StringDecoder
,
StringEncoder
,
StringIndenter
Constructor Summary | |
StringToolbox()
|
Method Summary | |
static boolean |
contains(java.lang.String string,
char c)
Determines whether a string contains a character. |
static boolean |
contains(java.lang.String string,
java.lang.String substring)
Determines whether a string contains a substring. |
static int |
count(java.lang.String string,
char c)
Counts character occurrences. |
static int |
count(java.lang.String string,
java.lang.String substring)
Counts substring occurences. |
static int |
findDifference(java.lang.String s1,
java.lang.String s2)
Finds first difference. |
static java.lang.String |
getCommonSuffix(java.lang.String s1,
java.lang.String s2)
Determines common suffix. |
static java.lang.String |
left(java.lang.String s,
int len)
|
static boolean |
looksLikeAnEmailAddress(java.lang.String s)
Determines if string looks like an email address. |
static java.lang.String |
minimizeSpaces(java.lang.String s)
Removes excess spaces. |
static java.lang.String |
repeat(char s,
int n)
Creates string by repeating character. |
static java.lang.String |
repeat(java.lang.String s,
int n)
Creates string by repeating string. |
static java.lang.String |
replace(java.lang.String source,
java.lang.String before,
java.lang.String after)
Search and replace. |
static java.lang.String |
right(java.lang.String s,
int len)
|
static java.lang.String[] |
splitString(java.lang.String s,
java.lang.String d)
Divides string into tokens. |
static java.lang.String |
toInitialCaps(java.lang.String s)
Converts string to "title" case. |
static java.lang.String |
trim(java.lang.String s,
char c)
Trims characters from both ends of string. |
static java.lang.String |
trimTrailing(java.lang.String s,
char c)
Trims trailing characters. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StringToolbox()
Method Detail |
public static final boolean contains(java.lang.String string, char c)
Details: contains
determines whether c is contained within string, returning true
if it is, false
otherwise.
string
- the stringc
- the characterpublic static final boolean contains(java.lang.String string, java.lang.String substring)
Details: contains
determines whether substring is contained within string, returning true
if it is, false
if it is not.
string
- the stringsubstring
- the substringpublic static final int count(java.lang.String string, char c)
Details: count
determines the number of occurrences of a character in a string.
string
- the string to searchc
- the characterpublic static final int count(java.lang.String string, java.lang.String substring)
Details: count
determines the number of occurrences of a substring string inside another string. Overlapping substrings are counted. For example, the call
count ("banana", "ana")
returns 2.
string
- the string to searchsubstring
- the substringpublic static final int findDifference(java.lang.String s1, java.lang.String s2)
Details: findDifference compares two strings, character for character, starting with the first character, and scanning until a character mismatch is encountered, or until the shorter string has run out of characters. If a mismatch is encountered, the index of the mismatch is returned. If no mismatches are found but the strings have unequal lengths, the length of the shorter string is returned. If no mismatch is found and the strings have equal length, then the strings are identical and -1 is returned.
s1
- the first strings2
- the second stringpublic static final java.lang.String getCommonSuffix(java.lang.String s1, java.lang.String s2)
Details: getCommonSuffix returns the longest string that is a suffix to both given strings.
s1
- the first strings2
- the second stringpublic static java.lang.String left(java.lang.String s, int len)
public static final java.lang.String minimizeSpaces(java.lang.String s)
Details: minimizeSpaces removes excess white spaces from the ends and middle of the given string. Space characters are identified as StringTokenizer identifies them. A space is considered excess if any of the following conditions are true:
All white spaces are converted to normal spaces in the output string.
s
- the string to prunepublic static final java.lang.String repeat(char s, int n)
Details: repeat
creates a new string by repeating a character. For example, the call
repeat ('#', 3)
produces the string "###". A zero-
s
- the character to repeatn
- the repeat countpublic static final java.lang.String repeat(java.lang.String s, int n)
Details: repeat
creates a new String
by repeating and concatenating the contents of another String
(s). For example, the call
repeat ("Hello", 3)
produces the string "HelloHelloHello". repeat
returns a zero-length string if the repeat count (n) is less than 1.
s
- the string to repeatn
- the repeat countpublic static java.lang.String replace(java.lang.String source, java.lang.String before, java.lang.String after)
Details: replace
scans source for substrings matching before, from left to right, and replaces all occurrences found with after. If a matching substring is found, the replacement is made and then the scan picks up after the last character of the substring. The result is returned in a new string. If no replacements were made, the original String
instance is returned.
source
- the source stringbefore
- the substring to search forafter
- what to replace before withpublic static java.lang.String right(java.lang.String s, int len)
public static final java.lang.String[] splitString(java.lang.String s, java.lang.String d)
Details: splitString
breaks a string (s) into an array of substrings with the delimeters removed. The delimeter characters are listed in a separate string (d).
java.util.StringTokenizer
offers similar functionality. This implementation differs by the fact that it returns all of the tokens at once, using a String
array, and does not require the explicit creation of a tokenizer object or enumeration handling.
s
- the string to splitd
- the delimeterspublic static final java.lang.String toInitialCaps(java.lang.String s)
Details: This method converts the first character of every run of letters in the given string (s) to upper case, making the string appear in "title" format. For the purposes of conversion, apostrophes occuring immediately after letters are also treated as letters. This method may not be appropriate for some strings, particularly those containing Roman numerals and other words where more than one character should be capitalized.
Examples:
MacDonald's | Macdonald's |
yo-yos | Yo-Yos |
part | Part |
III | Iii |
s
- the string to convertpublic static final java.lang.String trim(java.lang.String s, char c)
Details: trim
removes the given character (c) from both ends of the given string (s). For example, the call
trimTrailing ("sizes", 's')
returns the string "ize".
s
- the string to editn
- the character to trimpublic static final java.lang.String trimTrailing(java.lang.String s, char c)
Details: trimTrailing
trims the specified character (c) from the end of the given string (s) if the string ends with one or more repetitions of that character. For example, the call
removeTrailing ("Tennessee", 'e')
returns the string "Tenness".
s
- the string to editn
- the trailing character to removepublic static final boolean looksLikeAnEmailAddress(java.lang.String s)
Details: looksLikeAnEmailAddress
analyzes the given string (s) and determines whether it looks like an email address. If it does, looksLikeAnEmailAddress
returns true
, false
otherwise.
See
for more information on the forms of email addresses accepted by this function.lava.io.StreamParser.tryEmailAddress
s
- the string to test
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |