Package com.sk89q.util
Class StringUtil
java.lang.Object
com.sk89q.util.StringUtil
String utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Find the Levenshtein distance between two Strings.static String
joinQuotedString
(String[] str, String delimiter, int initialIndex, String quote) Join an array of strings into a string.static String
joinString
(int[] str, String delimiter, int initialIndex) Join an array of strings into a string.static String
joinString
(Object[] str, String delimiter, int initialIndex) Join an array of strings into a string.static String
joinString
(String[] str, String delimiter) Join an array of strings into a string.static String
joinString
(String[] str, String delimiter, int initialIndex) Join an array of strings into a string.static String
joinString
(Collection<?> str, String delimiter, int initialIndex) Join an list of strings into a string.static <T extends Enum<?>>
TparseListInQuotes
(String[] input, char delimiter, char quoteOpen, char quoteClose) parseListInQuotes
(String[] input, char delimiter, char quoteOpen, char quoteClose, boolean appendLeftover) static String
trimLength
(String str, int len) Trim a string if it is longer than a certain length.
-
Method Details
-
trimLength
Trim a string if it is longer than a certain length.- Parameters:
str
- the stringlen
- the length to trim to- Returns:
- a new string
-
joinString
Join an array of strings into a string.- Parameters:
str
- the string arraydelimiter
- the delimiterinitialIndex
- the initial index to start form- Returns:
- a new string
-
joinQuotedString
public static String joinQuotedString(String[] str, String delimiter, int initialIndex, String quote) Join an array of strings into a string.- Parameters:
str
- the string arraydelimiter
- the delimiterinitialIndex
- the initial index to start formquote
- the character to put around each entry- Returns:
- a new string
-
joinString
Join an array of strings into a string.- Parameters:
str
- the string arraydelimiter
- the delimiter- Returns:
- a new string
-
joinString
Join an array of strings into a string.- Parameters:
str
- an array of objectsdelimiter
- the delimiterinitialIndex
- the initial index to start form- Returns:
- a new string
-
joinString
Join an array of strings into a string.- Parameters:
str
- a list of integersdelimiter
- the delimiterinitialIndex
- the initial index to start form- Returns:
- a new string
-
joinString
Join an list of strings into a string.- Parameters:
str
- a list of stringsdelimiter
- the delimiterinitialIndex
- the initial index to start form- Returns:
- a new string
-
getLevenshteinDistance
Find the Levenshtein distance between two Strings.
This is the number of changes needed to change one String into another, where each change is a single character modification (deletion, insertion or substitution).
The previous implementation of the Levenshtein distance algorithm was from http://www.merriampark.com/ld.htm
Chas Emerick has written an implementation in Java, which avoids an OutOfMemoryError which can occur when my Java implementation is used with very large strings.
This implementation of the Levenshtein distance algorithm is from http://www.merriampark.com/ldjava.htmStringUtil.getLevenshteinDistance(null, *) = IllegalArgumentException StringUtil.getLevenshteinDistance(*, null) = IllegalArgumentException StringUtil.getLevenshteinDistance("","") = 0 StringUtil.getLevenshteinDistance("","a") = 1 StringUtil.getLevenshteinDistance("aaapppp", "") = 7 StringUtil.getLevenshteinDistance("frog", "fog") = 1 StringUtil.getLevenshteinDistance("fly", "ant") = 3 StringUtil.getLevenshteinDistance("elephant", "hippo") = 7 StringUtil.getLevenshteinDistance("hippo", "elephant") = 7 StringUtil.getLevenshteinDistance("hippo", "zzzzzzzz") = 8 StringUtil.getLevenshteinDistance("hello", "hallo") = 1
- Parameters:
s
- the first String, must not be nullt
- the second String, must not be null- Returns:
- result distance
- Throws:
IllegalArgumentException
- if either String inputnull
-
lookup
-
parseListInQuotes
-
parseListInQuotes
-