- string.explode()
- string.implode()
- string.trim()
- string.random()
- string.toUnicode()
- string.likeness()
Splits string 'str' by delimiter 'delim'. Returns results as a table.
If 'str' ends with the delimiter, it will not include that empty/blank value.
@code() local data = "abc,def,ghi,"; local results = string.explode(data, ","); -- Split 'data' by commas table.print(results); @endcode @code() 1: "abc" 2: "def" 3: "ghi" @endcodeThe exact opposite of string.explode(); this function takes a table of elements and joins them by a glue string.
@code() local items = {1, 2, 3, 4} print(string.implode(items, ",")) -- Prints: 1,2,3,4 @endcode"Trim" whitespace off head and tail of string 'str', return result.
@code() local data = " \tTrim excess white space from this string \t "; print(string.trim(data)); @endcode @code() Trim excess white space from this string @endcodeCreates a random string based on the given type and with 'length' characters. 'type' should be:
| Alpha-numeric (both upper and lower case) characters | |
| Letters only (both upper and lower case) | |
| Numeric characters only |
Attempt to convert the input string 'str' to a wide string, returns the result.
Computes how alike two strings are and returns two numbers: 'percent' (a float) of how similar they are and 'differences' (an integer) which is the number of differences found between them. This function is case-sensitive; if you would like to have it be case insensitive, consider casting both strings to lower-case before passing them to this function.
This function uses the Levenshtein distance algorithm. An important thing to note is that it is not a direct column-to-column comparison, but will instead consider string shifting where available. For example:
@code() local str1 = "HelloWorld"; local str2 = "Hello World": print("Likeness:", string.likeness(str1, str2)); --[[ Prints: Likeness: 90.909090 1 These two should have only one difference: the space between them! They are ~91% similar NOT 6 differences (everything after 'Hello'). --]] local str1 = "Hello World"; local str2 = "hello world": print("Likeness:", string.likeness(str1, str2)); --[[ Prints: Likeness: 81.818181 2 These two strings have two differences (the 'W' and 'H' due to case-sensitivity) --]] @endcodePage last updated at 2021-11-07 23:19:13