Module string.lua

String operation extensions

Functions

string.endswith (s, value) Check if a string ends with a value
string.join (s, other) Concatenate a list/table of strings with another string as the delimiter
string.replace (s, sub, rep, limit) Replace occurrences of a substring in a string
string.split (s, delim) Split a string by a delimiter into a table of strings
string.startswith (s, value) Check if a string starts with a value
string.strip (s, remove) Strip characters from the beginning and end of a string

Metatable functions

metafuncs.add (s, other) Add strings together with + operator
metafuncs.call (s, i, j) Slice a string into a smaller string.
metafuncs.index (s, i) Index a single character in a string.
metafuncs.mul (s, other) Multiply a string to repeat it
metafuncs.pairs (s) Iterate over the characters in a string


Functions

string.endswith (s, value)
Check if a string ends with a value

Parameters:

Returns:

    boolean
string.join (s, other)
Concatenate a list/table of strings with another string as the delimiter

Parameters:

Returns:

    string
string.replace (s, sub, rep, limit)
Replace occurrences of a substring in a string

Parameters:

Returns:

    string
string.split (s, delim)
Split a string by a delimiter into a table of strings

Parameters:

Returns:

    list
string.startswith (s, value)
Check if a string starts with a value

Parameters:

Returns:

    boolean
string.strip (s, remove)
Strip characters from the beginning and end of a string

Parameters:

Returns:

    string

Metatable functions

metafuncs.add (s, other)
Add strings together with + operator

Parameters:

Usage:

    "abc" + "cde" => "abccde"
metafuncs.call (s, i, j)
Slice a string into a smaller string. (see http://lua-users.org/wiki/StringIndexing)

Parameters:

  • s
  • i
  • j

Usage:

    x = 'abcde'
    x(2, 4) => 'bcd'
    x{1, -2, 3} => 'adc'
metafuncs.index (s, i)
Index a single character in a string. (see http://lua-users.org/wiki/StringIndexing)

Parameters:

  • s
  • i

Usage:

    x = 'abcde'
    x[3] == x[-3] == 'c'
    x.<command> == function or nil
metafuncs.mul (s, other)
Multiply a string to repeat it

Parameters:

  • s
  • other

Usage:

    "ab" * 3 => "ababab"
metafuncs.pairs (s)
Iterate over the characters in a string

Parameters:

  • s

Usage:

    x = 'ab'
    for i, v in pairs(x) do print(i, v) end
    prints ->
        1, a
        2, b
generated by LDoc 1.4.6 Last updated 2018-11-10 22:55:04