stendhal/doc/mkdocs/lua/supplemental_methods/strings.md
2022-02-11 02:54:04 -08:00

2.3 KiB

Strings

[TOC]

String Manipulation

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


string.startsWith

string.startsWith(st, prefix)

  • Checks if a string begins with a set of characters.
  • Parameters:
    • st: The string to be checked.
    • prefix: The prefix to be compared with.
  • Returns: true if prefix matches the beginning characters of st.
  • Aliases:
    • string.beginsWith

string.endsWith

string.endsWith(st, suffix)

  • Checks if a string ends with a set of characters.
  • Parameters:
    • st: The string to be checked.
    • suffix: The suffix to be compared with.
  • Returns: true if suffix matches then end characters of st.

string.isNumber

string.isNumber(st)

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

string.trim

string.trim(st)

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

string.ltrim

string.ltrim(st)

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

string.rtrim

string.rtrim(st)

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

string.builder

string.builder(st)

  • Creates a new instance of {@link java.lang.StringBuilder}.
  • Parameters:
    • st: (optional) String to append on instantiation.
  • Returns: new StringBuilder instance.