Package org.kissweb
Class StringUtils
java.lang.Object
org.kissweb.StringUtils
This class contains many methods used to manipulate
Strings.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringStrip the spaces on both ends of a string.static StringConvertCharactertoStringcorrectly handling nulls.static StringAn APL-like DROP function.static StringfindClosestMatch(Vector<String> strings, String input) Finds the string from the given vector of strings that most closely matches the input string.static StringhtmlToText(String html) Converts HTML text to plain text.static booleanString null or empty test.static StringJoin rows or a String array into a String separated by a delimiter.static StringStrip the spaces at the beginning of a string.static char[]movmem(char[] f, int fi, char[] t, int ti, int n) Moves characters from one array to another.static StringrightStrip(String s) Strip the spaces of the end of a string.static String[]Splits a string into an array of substrings based on a specified delimiter character.static StringC-like sprintf method.static CharacterConvertStringtoCharactercorrectly handling nulls and zero length strings.static intstrLength(char[] v) static StringThis method provides the ability to get a substring of a string by providing a starting location and a length.static char[]take(char[] s, int n) static StringAn APL-like TAKE function.static StringConverts a string to ASCII by replacing non-ASCII characters with their ASCII approximations and removing other non-ASCII characters.
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
substring
This method provides the ability to get a substring of a string by providing a starting location and a length.- Parameters:
str- the String to be substring'edfrom- index of the starting position (starting at 0)n- number of characters to take- Returns:
- the sub-string
-
take
An APL-like TAKE function. Assures that the string isncharacters long.
If the string is shorter thannit is padded by spaces.
If the string is longer thannit is cut short.
Ifnis negative, the same thing occurs but it starts at the back of the string. Thus padding or cutting of the string occur at the start of the string.- Parameters:
s-n-- Returns:
- See Also:
-
take
public static char[] take(char[] s, int n) -
strLength
public static int strLength(char[] v) -
movmem
public static char[] movmem(char[] f, int fi, char[] t, int ti, int n) Moves characters from one array to another. The two arrays may be the same array. Correctly handles overlapping regions.- Parameters:
f- the from or source arrayfi- the index into f to start att- the to or destination arrayti- the starting index into tn- the number of characters to move- Returns:
- the destination array
-
drop
An APL-like DROP function. Dropsncharacters from the string.
Ifnis positive,ncharacters get dropped from the beginning of the string.
Ifnis negative,ncharacters get dropped from the end of the string.
Ifnis greater than the length of the string, "" is returned.- Parameters:
s-n-- Returns:
- See Also:
-
rightStrip
Strip the spaces of the end of a string.- Parameters:
s-- Returns:
-
leftStrip
Strip the spaces at the beginning of a string.- Parameters:
s-- Returns:
-
centerStrip
Strip the spaces on both ends of a string.- Parameters:
s-- Returns:
-
sprintf
C-like sprintf method. Format a string according to the format inserting the arguments as placed in the format string.- Parameters:
fmt- format stringarg1- consecutive values used by the format string- Returns:
- See Also:
-
join
Join rows or a String array into a String separated by a delimiter.- Parameters:
strings-separator-- Returns:
-
isEmpty
String null or empty test. Returns true if string is null or empty.- Parameters:
str-- Returns:
-
stringToCharacter
ConvertStringtoCharactercorrectly handling nulls and zero length strings.- Parameters:
s-- Returns:
-
characterToString
ConvertCharactertoStringcorrectly handling nulls.- Parameters:
c-- Returns:
-
split
Splits a string into an array of substrings based on a specified delimiter character. Unlike the Java version, this one correctly handles empty strings.- Parameters:
s- the string to be splitr- the delimiter regex- Returns:
- an array of substrings
-
htmlToText
Converts HTML text to plain text. Also corrects some Unicode characters.- Parameters:
html- the HTML text to be converted- Returns:
- the converted plain text
-
findClosestMatch
Finds the string from the given vector of strings that most closely matches the input string.
This method normalizes the input and the vector strings by removing spaces and converting to lowercase before comparing them using the Jaro-Winkler distance algorithm.- Parameters:
strings- a vector of strings to compare against the input stringinput- the input string that may contain typos, case, or space differences- Returns:
- the string from the vector that most closely matches the input string
-
toAscii
Converts a string to ASCII by replacing non-ASCII characters with their ASCII approximations and removing other non-ASCII characters.- Parameters:
input- the original string- Returns:
- the ASCII string
-