Extends Lua 5.2 string.
local string = require('__stdlib__/stdlib/utils/string')
String.trim(s) | Returns a copy of the string with any leading or trailing whitespace from the string removed. |
String.starts_with(s, start) | Tests if a string starts with a given substring. |
String.ends_with(s, ends) | Tests if a string ends with a given substring. |
String.contains(s, contains) | Tests if a string contains a given substring. |
String.is_empty(s) | Tests whether a string is empty. |
String.is_alpha(s) | does s only contain alphabetic characters? |
String.is_digit(s) | does s only contain digits? |
String.is_alnum(s) | does s only contain alphanumeric characters? |
String.is_space(s) | does s only contain spaces? |
String.is_lower(s) | does s only contain lower case characters? |
String.is_upper(s) | does s only contain upper case characters? |
String.title(s) | iniital word letters uppercase (‘title case’). |
String.shorten(s, w, tail) | Return a shortened version of a string. |
String.join(s, seq) | concatenate the strings using this string as a delimiter. |
String.ljust(s, w[, ch=' ']) | left-justify s with width w. |
String.rjust(s, w[, ch=' ']) | right-justify s with width w. |
String.center(s, w[, ch=' ']) | center-justify s with width w. |
String.split(s[, sep="."][, pattern=false][, func]) | Splits a string into an array. |
String.ordinal_suffix(n, prepend_number) | Return the ordinal suffix for a number. |
String.exponent_number(str) | Convert a metric string prefix to a number value. |
Returns a copy of the string with any leading or trailing whitespace from the string removed.
Parameters:
Tests if a string starts with a given substring.
Parameters: Returns:
Tests if a string ends with a given substring.
Parameters: Returns:
Tests if a string contains a given substring.
Parameters: Returns:
Tests whether a string is empty.
Parameters:
does s only contain alphabetic characters?
Parameters:
does s only contain digits?
Parameters:
does s only contain alphanumeric characters?
Parameters:
does s only contain spaces?
Parameters:
does s only contain lower case characters?
Parameters:
does s only contain upper case characters?
Parameters:
iniital word letters uppercase (‘title case’).
Here ‘words’ mean chunks of non-space characters.
Parameters:Return a shortened version of a string.
Fits string within w characters. Removed characters are marked with ellipsis.
Parameters:('1234567890'):shorten(8) == '12345...'
('1234567890'):shorten(8, true) == '...67890'
('1234567890'):shorten(20) == '1234567890'
concatenate the strings using this string as a delimiter.
Parameters:
(' '):join {1,2,3} == '1 2 3'
left-justify s with width w.
Parameters:
right-justify s with width w.
Parameters:
center-justify s with width w.
Parameters:
Splits a string into an array.
Note: Empty split substrings are not included in the resulting table.
For example, string.split("foo.bar...", ".", false)
results in the table {"foo", "bar"}
.