From the reference libraryRedM

String <BadgeShared/>

jo_libs/modules/string/shared.md

String <BadgeShared/>

The String module extends Lua's native string capabilities by adding powerful utility functions for enhanced string manipulation. It seamlessly integrates with the standard string library by augmenting the string metatable, providing developers with a comprehensive toolkit for case conversion, string splitting, whitespace trimming, version number handling, and hexadecimal conversions.

string Methods > string:compareVersionWith()

<!-- @include: ./slots/headers.md#shared|string:compareVersionWith -->

Compare two version strings <br>

<!-- @include: ./slots/descriptions.md#shared|string:compareVersionWith -->

string Methods > string:compareVersionWith() > Syntax

string:compareVersionWith(version)

string Methods > string:compareVersionWith() > Parameters

version : string

The string version to compare to

string Methods > string:compareVersionWith() > Return Value

Type : integer

-1 if the version is older, 0 if it's the same and 1 if it's more recent

<!-- @include: ./slots/examples.md#shared|string:compareVersionWith -->

<!-- @include: ./slots/footers.md#shared|string:compareVersionWith -->


string Methods > string:convertVersion()

<!-- @include: ./slots/headers.md#shared|string:convertVersion -->

Convert a version string (like "1.2.3") to a numeric value <br>

<!-- @include: ./slots/descriptions.md#shared|string:convertVersion -->

string Methods > string:convertVersion() > Syntax

string:convertVersion()

string Methods > string:convertVersion() > Return Value

Type : number

The converted numeric version

<!-- @include: ./slots/examples.md#shared|string:convertVersion -->

<!-- @include: ./slots/footers.md#shared|string:convertVersion -->


string Methods > string:firstToUpper()

<!-- @include: ./slots/headers.md#shared|string:firstToUpper -->

Return the string with the first letter in uppercase <br>

<!-- @include: ./slots/descriptions.md#shared|string:firstToUpper -->

string Methods > string:firstToUpper() > Syntax

string:firstToUpper()

string Methods > string:firstToUpper() > Return Value

Type : string

Return the string with the first letter in uppercase

<!-- @include: ./slots/examples.md#shared|string:firstToUpper -->

<!-- @include: ./slots/footers.md#shared|string:firstToUpper -->


string Methods > string:removeAccent()

<!-- @include: ./slots/headers.md#shared|string:removeAccent -->

A function to remove all accent in a string <br>

<!-- @include: ./slots/descriptions.md#shared|string:removeAccent -->

string Methods > string:removeAccent() > Syntax

string:removeAccent()

string Methods > string:removeAccent() > Return Value

Type : string

A string without accent

<!-- @include: ./slots/examples.md#shared|string:removeAccent -->

<!-- @include: ./slots/footers.md#shared|string:removeAccent -->


string Methods > string:split()

<!-- @include: ./slots/headers.md#shared|string:split -->

Split a string into parts based on a delimiter <br>

<!-- @include: ./slots/descriptions.md#shared|string:split -->

string Methods > string:split() > Syntax

string:split(delimiter, pieces)

string Methods > string:split() > Parameters

delimiter : string

The character(s) to split the string on

pieces : number <BadgeOptional />

The maximum number of pieces to split into

string Methods > string:split() > Return Value

Type : table

Array of string parts

<!-- @include: ./slots/examples.md#shared|string:split -->

<!-- @include: ./slots/footers.md#shared|string:split -->


string Methods > string:toHex()

<!-- @include: ./slots/headers.md#shared|string:toHex -->

Convert a hexadecimal string to a number, handling signed values <br>

<!-- @include: ./slots/descriptions.md#shared|string:toHex -->

string Methods > string:toHex() > Syntax

string:toHex()

string Methods > string:toHex() > Return Value

Type : number

The converted numeric value

<!-- @include: ./slots/examples.md#shared|string:toHex -->

<!-- @include: ./slots/footers.md#shared|string:toHex -->


string Methods > string:trim()

<!-- @include: ./slots/headers.md#shared|string:trim -->

Remove whitespace from both ends of a string <br>

<!-- @include: ./slots/descriptions.md#shared|string:trim -->

string Methods > string:trim() > Syntax

string:trim()

string Methods > string:trim() > Return Value

Type : string

The trimmed string

<!-- @include: ./slots/examples.md#shared|string:trim -->

<!-- @include: ./slots/footers.md#shared|string:trim -->

String Functions > string.compare()

<!-- @include: ./slots/headers.md#shared|string.compare -->

A function to compare two strings <br>

<!-- @include: ./slots/descriptions.md#shared|string.compare -->

String Functions > string.compare() > Syntax

string.compare(a, b, caseSensitive)

String Functions > string.compare() > Parameters

a : string

The 1st string

b : string

The 2nd string

caseSensitive : boolean

If the compare is case sensitive<br>default: false

String Functions > string.compare() > Return Value

Type : integer

-1 if a is previous, 0 if both are same and 1 if a is after

<!-- @include: ./slots/examples.md#shared|string.compare -->

<!-- @include: ./slots/footers.md#shared|string.compare -->


String Functions > string.spaceNumber()

<!-- @include: ./slots/headers.md#shared|string.spaceNumber -->

Convert a integer|number to a spaced number <br>

<!-- @include: ./slots/descriptions.md#shared|string.spaceNumber -->

String Functions > string.spaceNumber() > Syntax

string.spaceNumber(number, decimal)

String Functions > string.spaceNumber() > Parameters

number : integer|number

The number to convert

decimal : integer <BadgeOptional />

The number of decimal <br> default: 0

<!-- @include: ./slots/examples.md#shared|string.spaceNumber -->

<!-- @include: ./slots/footers.md#shared|string.spaceNumber -->

string Methods > string:extractConvarComparator()

<!-- @include: ./slots/headers.md#shared|string:extractConvarComparator -->

Extract resource, convar, comparator and value from a "resourceName[:convar](< > <= >= ==)value" string <br> The ":convar" part is optional (eg. "rsg-core>=2.0.0") <br>

<!-- @include: ./slots/descriptions.md#shared|string:extractConvarComparator -->

string Methods > string:extractConvarComparator() > Syntax

string:extractConvarComparator()

string Methods > string:extractConvarComparator() > Return Value

Type : string?

<!-- @include: ./slots/examples.md#shared|string:extractConvarComparator -->

<!-- @include: ./slots/footers.md#shared|string:extractConvarComparator -->


Back to documentation