MiscClient

compareStrings

COMPARE_STRINGS0x1E34710ECD4AB0EB

The GTA V native COMPARE_STRINGS of the MISC namespace, as LS:MP client scripts call it: the global function compareStrings, in JavaScript and in Lua.

SignatureJavaScript
compareStrings(
  str1: string,
  str2: string,
  matchCase: boolean,
  maxLength: number
): number
SignatureLua
compareStrings(
  str1: string,
  str2: string,
  matchCase: boolean,
  maxLength: integer
): integer

Usage

JavaScript
const result = compareStrings(str1, str2, matchCase, maxLength);
Lua
local result = compareStrings(str1, str2, matchCase, maxLength)

Parameters

ParameterTypeJavaScriptLua
str1stringstringstring
str2stringstringstring
matchCaseBOOLbooleanboolean
maxLengthintnumberinteger

Returns

int JavaScript number, Lua integer

Notes

From the community native database. Names are LS:MP’s; samples may be written for C++ or another framework.

Compares two strings up to a specified number of characters.

Parameters:
str1 - String to be compared.
str2 - String to be compared.
matchCase - Comparison will be case-sensitive.
maxLength - Maximum number of characters to compare. A value of -1 indicates an infinite length.

Returns:
A value indicating the relationship between the strings:
<0 - The first non-matching character in 'str1' is less than the one in 'str2'. (e.g. 'A' < 'B', so result = -1)
0 - The contents of both strings are equal.
>0 - The first non-matching character in 'str1' is less than the one in 'str2'. (e.g. 'B' > 'A', so result = 1)

Examples:

compareStrings("STRING", "string", false, -1); // 0; equal
compareStrings("TESTING", "test", false, 4); // 0; equal
compareStrings("R2D2", "R2xx", false, 2); // 0; equal
compareStrings("foo", "bar", false, -1); // 4; 'f' > 'b'
compareStrings("A", "A", true, 1); // 0; equal

When comparing case-sensitive strings, lower-case characters are greater than upper-case characters:

compareStrings("A", "a", true, 1); // -1; 'A' < 'a'
compareStrings("a", "A", true, 1); // 1; 'a' > 'A'

Reference

Namespace
Misc MISC
In the game
int COMPARE_STRINGS(const char* str1, const char* str2, BOOL matchCase, int maxLength)
Hash
0x1E34710ECD4AB0EB

Open in the interactive natives reference