Skip to content

`Lua Addons: String

GhostglowDev edited this page Mar 21, 2024 · 2 revisions
local string = require "ghostutil.lua-addons.string"

See source code

split(str:String, delimeter:String) -> Array[Null[String]]

Splits the string with the delimeter to a table of strings. If fails, returns an empty table

  • str: String to split
  • delimeter: The string that splits str

Example:

string.split("i like-cats", "-")
-- returns: {"i like", "cats"}

shuffle(str:String) -> String

Shuffles the given string. If fails, returns the original string

Example:

string.shuffle("hello world")

ltrim(str:String) -> String

Removes the spaces from the left ends. If fails, returns the original string

Example:

string.ltrim("  krill me ")
-- returns "krill me "

rtrim(str:String) -> String

Removes the spaces from the right ends. If fails, returns the original string

Example:

string.rtrim("  krill me ")
-- returns "  krill me"

trim(str:String) -> String

Removes the spaces from both ends. If fails, returns the original string

Example:

string.trim("  krill me ")
-- returns "krill me"

startwith(str:String, startsWith:String) -> Bool

Checks if the given string starts with startsWith

endswith(str:String, endsWith:String) -> Bool

Checks if the given string ends with endsWith

Example:

string.startswith("thisthing", "this")
-- returns true

string.endswith("thisthing", "this")
-- returns false