Loading content...
String
String helpers — trim, split, prefix/suffix checks, capitalize, random, pattern escape.
String helpers — trim, split, prefix/suffix checks, capitalize, random, pattern escape.
lib.string covers the common string operations. Shared (client + server).
| Function | Returns | Description |
|---|---|---|
trim(str) | string | Strip leading / trailing whitespace. |
split(str, sep) | string[] | Split on a literal separator; empty segments dropped. |
startsWith(str, prefix) | boolean | Whether str begins with prefix. |
endsWith(str, suffix) | boolean | Whether str ends with suffix (true if empty). |
capitalize(str) | string | Uppercase the first letter only. |
random(length, charset?) | string | Random string (default alphanumeric). |
escape(str) | string | Escape Lua pattern meta-characters. |
trim(str)stringsplit(str, sep)string[]startsWith(str, prefix)booleanstr begins with prefix.endsWith(str, suffix)booleanstr ends with suffix (true if empty).capitalize(str)stringrandom(length, charset?)stringescape(str)stringlocal clean = lib.string.trim(' hello ')
local parts = lib.string.split('a,b,,c', ',') -- { 'a', 'b', 'c' }
local token = lib.string.random(16)
local pin = lib.string.random(6, '0123456789')
local safe = lib.string.escape(userInput) -- before string.find / gsubsplit is literal (not a Lua pattern) and drops empty segments. random uses math.random — not for passwords/secrets. escape handles Lua patterns only — not SQL or HTML sanitizing.