Module string

This module extends the functionality contained in the string table for convenience.

See the official string documentation for other functions that are available in the string table.

Since the string table is the hardwired __index table for string objects you can call them using the short : notion.

Usage:

    local str = 'Hello World'
    print(string.startsWith(str, 'Hello'))     -- Prints true
    print(str:startsWith('Hello'))             -- Äquivalent to previous line
    
    -- Note that you have to put parentheses () around a string if you want to call a function on it directly
    print(('Hello World'):startsWith('Hello')) -- Prints true
    
    print(Array(str:split(' ')))               -- Prints {Hello, World}
    print(str:split(' ')[1])                   -- Prints Hello
    print(str:split(' ')[2])                   -- Prints World
    

Functions

contains (needle) Returns true iff the string contains the given substring.
endsWith (part) Checks whether the string ends with the given string.
split (sep) Splits the string into a table of strings by a given separator.
startsWith (part) Checks whether the string starts with the given string.
trim () Removes white spaces at the start and ending of the string.


Functions

contains (needle)
Returns true iff the string contains the given substring.

New feature:

    This is a new feature that was added in version 1.11.46

Parameters:

  • needle string The string to search for.

Returns:

    bool True if the needle is within the string.
endsWith (part)
Checks whether the string ends with the given string.

Parameters:

  • part string The string to check if it ends with it.

Returns:

    bool True iff self ends with the string part.
split (sep)
Splits the string into a table of strings by a given separator. Uses implementation from here.

Parameters:

  • sep string The literal separator pattern, e.g. ','

Returns:

    table A table that contains the remaining strings.
startsWith (part)
Checks whether the string starts with the given string.

Parameters:

  • part string The string to check if it starts with it.

Returns:

    bool True iff self starts with the string part.
trim ()
Removes white spaces at the start and ending of the string.

New feature:

    This is a new feature that was added in version 1.10.08

Returns:

    string The string without starting and ending spaces.
generated by LDoc 1.4.3 Last updated 2024-11-25 14:07:58