Skip to content

String Extensions

Side: Shared (Client + Server)

Extensions to Lua's built-in string library. Instance methods use the : syntax, static methods use . syntax.

Instance Methods

string:firstToUpper()

Capitalizes the first character of the string.

Returns: string


string:split(delimiter, max_parts?)

Splits a string by the given delimiter.

ParameterTypeDefaultDescription
delimiterstringSeparator pattern
max_partsinteger?nilMaximum number of parts (unlimited if omitted)

Returns: table (array of strings)


string:trim()

Removes leading and trailing whitespace.

Returns: string


string:toHex()

Converts a hex string to a number.

Returns: number


string:removeAccent()

Replaces accented characters with their ASCII equivalents.

Returns: string


string:convertVersion()

Converts a version string (e.g. "1.2.3") to a comparable number.

Returns: number


string:compareVersionWith(other)

Compares two version strings.

ParameterTypeDescription
otherstringVersion string to compare against

Returns: integer-1 if self is older, 0 if equal, 1 if self is newer.

Static Methods

string.spaceNumber(value, decimal_count?)

Formats a number with space-separated thousands.

ParameterTypeDefaultDescription
valuenumberNumber to format
decimal_countinteger?nilDecimal places to show

Returns: string


string.compare(first, second, case_sensitive?)

Natural sort comparison of two strings (numbers within strings are compared numerically).

ParameterTypeDefaultDescription
firststringFirst string
secondstringSecond string
case_sensitiveboolean?falseCase-sensitive comparison

Returns: integer-1, 0, or 1

Examples

lua
-- Capitalize
("hello"):firstToUpper()        -- "Hello"

-- Split
("a,b,c"):split(",")            -- { "a", "b", "c" }
("a,b,c,d"):split(",", 2)       -- { "a", "b,c,d" }

-- Trim
("  hello  "):trim()            -- "hello"

-- Remove accents
("cafe"):removeAccent()         -- "cafe"

-- Format numbers with spaces
string.spaceNumber(1234567)          -- "1 234 567"
string.spaceNumber(1234567.89, 2)    -- "1 234 567.89"

-- Version comparison
local v = "1.2.0"
v:compareVersionWith("1.1.0")   -- 1  (newer)
v:compareVersionWith("1.2.0")   -- 0  (equal)
v:compareVersionWith("1.3.0")   -- -1 (older)

-- Natural sort
string.compare("item2", "item10")    -- -1 (item2 comes before item10)

Premium RedM Scripts — Multi-Framework