stendhal/doc/mkdocs/lua/objects/strings.md
2023-05-17 02:08:58 -07:00

4.6 KiB


Contents

[TOC]


String Manipulation

Global table variable: string


Description

The following methods have been added to the built-in Lua string table.


Methods


string.builder

string.builder ()
string.builder (st)

string.endsWith

string.endsWith (st, suffix)
  • Checks if a string ends with a set of characters.
  • Parameters:
    • st: (string) The string to be checked.
    • suffix: (string) The suffix to be compared with.
  • Returns: (bool) true if suffix matches the end characters of st.
  • Aliases:
    • string.endswith

string.isNumber

string.isNumber (st)
  • Checks if a string contains numeric characters only.
  • Parameters:
    • st: (string) The string to be checked.
  • Returns: (bool) true if all characters are numeric, false otherwise.
  • Aliases:
    • string.isnumber
    • string.isNumeric
    • string.isnumeric

string.ltrim

string.ltrim (st)
  • Removes leading whitespace from a string.
  • Parameters:
    • st: (string) The string to be trimmed.
  • Returns: (string) Trimmed string.

string.rtrim

string.rtrim (st)
  • Removes trailing whitespace from a string.
  • Parameters:
    • st: (string) The string to be trimmed.
  • Returns: (string) Trimmed string.

string.split

string.split (str, delim)
  • Splits a string into a table.
  • Parameters:
    • str: (string) The string to be split.
    • delim: (string) The delimiter character(s) used to split the string.
  • Returns: (table) List of strings.

string.startsWith

string.startsWith (st, prefix)
  • Checks if a string begins with a set of characters.
  • Parameters:
    • st: (string) The string to be checked.
    • prefix: (string) The prefix to be compared with.
  • Returns: (bool) true if prefix matches the beginning characters of st.
  • Aliases:
    • string.startswith
    • string.beginsWith
    • string.beginswith

string.trim

string.trim (st)
  • Removes leading & trailing whitespace from a string.
  • Parameters:
    • st: (string) The string to be trimmed.
  • Returns: (string) Trimmed string.

string.valueOf

string.valueOf (obj)
  • Retrieves string value of an object.
  • Parameters:
    • obj: (Object) Object instance to be converted.
  • Returns: (string) String value of object.
  • Aliases:
    • string.valueof