Gameplay::compareStrings: Difference between revisions

From RAGE Multiplayer Wiki
(yay)
 
(yay)
Line 1: Line 1:
Compares two strings up to a specified number of characters.<br><br>Parameters:<br>str1 - String to be compared.<br>str2 - String to be compared.<br>matchCase - Comparison will be case-sensitive.<br>maxLength - Maximum number of characters to compare. A value of -1 indicates an infinite length.<br><br>Returns:<br>A value indicating the relationship between the strings:<br>&lt;0 - The first non-matching character in 'str1' is less than the one in 'str2'. (e.g. 'A' &lt; 'B', so result = -1)<br>0 - The contents of both strings are equal.<br>&gt;0 - The first non-matching character in 'str1' is less than the one in 'str2'. (e.g. 'B' &gt; 'A', so result = 1)<br><br>Examples:<br>GAMEPLAY::COMPARE_STRINGS('STRING', 'string', false, -1); // 0; equal<br>GAMEPLAY::COMPARE_STRINGS('TESTING', 'test', false, 4); // 0; equal<br>GAMEPLAY::COMPARE_STRINGS('R2D2', 'R2xx', false, 2); // 0; equal<br>GAMEPLAY::COMPARE_STRINGS('foo', 'bar', false, -1); // 4; 'f' &gt; 'b'<br>GAMEPLAY::COMPARE_STRINGS('A', 'A', true, 1); // 0; equal<br><br>When comparing case-sensitive strings, lower-case characters are greater than upper-case characters:<br>GAMEPLAY::COMPARE_STRINGS('A', 'a', true, 1); // -1; 'A' &lt; 'a'<br>GAMEPLAY::COMPARE_STRINGS('a', 'A', true, 1); // 1; 'a' &gt; 'A'
Compares two strings up to a specified number of characters.<br><br>Parameters:<br>str1 - String to be compared.<br>str2 - String to be compared.<br>matchCase - Comparison will be case-sensitive.<br>maxLength - Maximum number of characters to compare. A value of -1 indicates an infinite length.<br><br>Returns:<br>A value indicating the relationship between the strings:<br>&lt;0 - The first non-matching character in 'str1' is less than the one in 'str2'. (e.g. 'A' &lt; 'B', so result = -1)<br>0 - The contents of both strings are equal.<br>&gt;0 - The first non-matching character in 'str1' is less than the one in 'str2'. (e.g. 'B' &gt; 'A', so result = 1)<br><br>Examples:<br>GAMEPLAY::COMPARE_STRINGS('STRING', 'string', false, -1); // 0; equal<br>GAMEPLAY::COMPARE_STRINGS('TESTING', 'test', false, 4); // 0; equal<br>GAMEPLAY::COMPARE_STRINGS('R2D2', 'R2xx', false, 2); // 0; equal<br>GAMEPLAY::COMPARE_STRINGS('foo', 'bar', false, -1); // 4; 'f' &gt; 'b'<br>GAMEPLAY::COMPARE_STRINGS('A', 'A', true, 1); // 0; equal<br><br>When comparing case-sensitive strings, lower-case characters are greater than upper-case characters:<br>GAMEPLAY::COMPARE_STRINGS('A', 'a', true, 1); // -1; 'A' &lt; 'a'<br>GAMEPLAY::COMPARE_STRINGS('a', 'A', true, 1); // 1; 'a' &gt; 'A'
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">gameplay.compareStrings(str1, str2, matchCase, maxLength);</syntaxhighlight>
<syntaxhighlight lang="javascript">mp.game.gameplay.compareStrings(str1, str2, matchCase, maxLength);</syntaxhighlight>
=== Required Arguments ===
=== Required Arguments ===
*'''str1:''' String
*'''str1:''' String
Line 11: Line 11:
==Example==
==Example==
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
todo
// todo
</syntaxhighlight>
</syntaxhighlight>
==See also==
==See also==
{{Gameplay_function_c}}
{{Gameplay_s_function_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]
[[Category:TODO: Example]]

Revision as of 21:06, 6 May 2017

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:
GAMEPLAY::COMPARE_STRINGS('STRING', 'string', false, -1); // 0; equal
GAMEPLAY::COMPARE_STRINGS('TESTING', 'test', false, 4); // 0; equal
GAMEPLAY::COMPARE_STRINGS('R2D2', 'R2xx', false, 2); // 0; equal
GAMEPLAY::COMPARE_STRINGS('foo', 'bar', false, -1); // 4; 'f' > 'b'
GAMEPLAY::COMPARE_STRINGS('A', 'A', true, 1); // 0; equal

When comparing case-sensitive strings, lower-case characters are greater than upper-case characters:
GAMEPLAY::COMPARE_STRINGS('A', 'a', true, 1); // -1; 'A' < 'a'
GAMEPLAY::COMPARE_STRINGS('a', 'A', true, 1); // 1; 'a' > 'A'

Syntax

mp.game.gameplay.compareStrings(str1, str2, matchCase, maxLength);

Required Arguments

  • str1: String
  • str2: String
  • matchCase: Boolean
  • maxLength: int

Return value

  • int

Example

// todo

See also

Template:Gameplay s function c