Skip to content

String library

Peter edited this page Dec 28, 2023 · 1 revision

The library inserts some helpful functions into the default string metatable, meaning you don't have to do anything to get them.

Functions

string.randomString(length: number, chars: nil|string[]) -> string

Creates a random string of given length

Parameters

  • length: number - Length of string
  • chars: nil|string[] - Optional. Charset for random characters, if not provided uses default: 0-9,a-z,A-Z

Returns

  • string str - Random string of length from charset

string.cont(_str1, _str2) -> boolean

Checks if _str1 contains _str2

Parameters

  • _str1: string - String to check in
  • _str2: string - String to check for

Returns

  • boolean contains - If _str2 is in _str1

string.split(_str1, _sep) -> string[]

Splits _str1 on every occurrence of _sep

Parameters

  • _str1: string - String to split
  • _sep: string - String to split on

Returns

  • string[] sections - Sections of _str1 split around _sep

string.start(_str1, _str2) -> boolean

Checks if _str1 starts with _str2

Parameters

  • _str1: string - String to check in
  • _str2: string - String to check for

Returns

  • boolean starts - If _str1 starts with _str2

string.ends(_str1, _str2) -> boolean

Checks if _str1 ends with _str2

Parameters

  • _str1: string String to check in
  • _str2: string String to check for

Returns

  • boolean ends - If _str1 ends with _str2
Clone this wiki locally