utils.string
Methods33
function String.find(s: string | number, pattern: string | number, init: nil | integer, plain: nil | boolean) -> (start nil | integer, end nil | integer, captured ...nil | string)
function String.lower(s: string) -> string
function String.sub(s: string | number, i: integer, j: nil | integer) -> string
function String.byte(s: string, i: nil | integer, j: nil | integer) -> integer
function String.char(...: integer) -> string
function String.reverse(s: string) -> string
function String.dump(func: function, strip: nil | boolean) -> string
function String.rep(s: string, n: integer, sep: nil | string) -> string
function String.format(fmt: string, ...: any) -> string
function String.match(s: string, pattern: string, init: nil | integer) -> ...nil | string
function String.gsub(s: string | number, pattern: string | number, repl: table | string | number | fun(param: string) -> nil, n: nil | integer) -> (string, count integer)
function String.len(s: string) -> integer
function String.upper(s: string) -> string
function String.trim(s: string) -> a string
Returns a copy of the string with any leading or trailing whitespace from the string removed.
sstringthe string to remove leading or trailing whitespace from
astringcopy of the string without leading or trailing whitespace
function String.starts_with(s: string, start: string) -> boolean
Tests if a string starts with a given substring.
sstringthe string to check for the start substring
startstringthe substring to test for
- boolean
true if the start substring was found in the string
function String.ends_with(s: string, ends: string) -> boolean
Tests if a string ends with a given substring.
sstringthe string to check for the end substring
endsstringthe substring to test for
- boolean
true if the end substring was found in the string
function String.contains(s: string, contains: string) -> boolean
Tests if a string contains a given substring.
sstringthe string to check for the substring
containsstringthe substring to test for
- boolean
true if the substring was found in the string
function String.is_empty(s: string) -> boolean
Tests whether a string is empty.
sstringthe string to test
- boolean
true if the string is empty
function String.is_alpha(s) -> boolean
does s only contain alphabetic characters? @string s a string
function String.is_digit(s) -> boolean
does s only contain digits? @string s a string
function String.is_alnum(s) -> boolean
does s only contain alphanumeric characters? @string s a string
function String.is_space(s) -> boolean
does s only contain spaces? @string s a string
function String.is_lower(s) -> boolean
does s only contain lower case characters? @string s a string
function String.is_upper(s) -> boolean
does s only contain upper case characters? @string s a string
function String.title(s) -> any
iniital word letters uppercase ('title case'). Here 'words' mean chunks of non-space characters. @string s the string @return a string with each word's first letter uppercase
function String.shorten(s, w, tail) -> any
Return a shortened version of a string. Fits string within w characters. Removed characters are marked with ellipsis. @string s the string @int w the maxinum size allowed @bool tail true if we want to show the end of the string (head otherwise) @usage ('1234567890'):shorten(8) == '12345...' @usage ('1234567890'):shorten(8, true) == '...67890' @usage ('1234567890'):shorten(20) == '1234567890'
function String.join(s, seq) -> string
concatenate the strings using this string as a delimiter. @string s the string @param a seq table of strings or numbers @usage (' '):join {1,2,3} == '1 2 3'
function String.ljust(s, w, ch) -> any
left-justify s with width w. @string s the string @int w width of justification @string[opt=' '] ch padding character
function String.rjust(s, w, ch) -> any
right-justify s with width w. @string s the string @int w width of justification @string[opt=' '] ch padding character
function String.center(s, w, ch) -> any
center-justify s with width w. @string s the string @int w width of justification @string[opt=' '] ch padding character
function String.split<T>(s: string, sep: nil | string, pattern: nil | boolean, func: fun(value: string) -> T | nil) -> T[]
Splits a string into an array. Note: Empty split substrings are not included in the resulting table.
function String.ordinal_suffix(n: number, prepend_number: boolean) -> string
Return the ordinal suffix for a number.
nnumberprepend_numberbooleanif the passed number should be pre-pended
- string
the ordinal suffix
function String.exponent_number(str: string) -> float
Convert a metric string prefix to a number value.
Fields1
String.gmatch : fun(s: string, pattern: string) -> fun() -> ...nil | string | fun(s: string, pattern: string, init: nil | integer) -> fun() -> ...nil | string