Utf8.ncasecmp: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Shared function}} Compares two strings in lower-case and returns the difference as a number value. ==Syntax== <syntaxhighlight lang="lua">int utf8.ncasecmp ( string a, string b )...")
 
m (tweaks)
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
{{Shared function}}
{{Shared function}}


Compares two strings in lower-case and returns the difference as a number value.
Compares two strings in lower-case and returns the difference indicator (see table below) as an integer value.


==Syntax==
==Syntax==
Line 12: Line 12:


===Returns===
===Returns===
Returns a ''number'', which indicates the difference, see the table below for further information.
Returns an ''integer'', which indicates the difference, see the table below for further information.


===Indicators===
===Indicators===

Latest revision as of 18:43, 15 February 2016

Compares two strings in lower-case and returns the difference indicator (see table below) as an integer value.

Syntax

int utf8.ncasecmp ( string a, string b )

Required Arguments

  • a: A string character sequence
  • b: A string character sequence

Returns

Returns an integer, which indicates the difference, see the table below for further information.

Indicators

Value Meaning
-1
a < b
0
a == b
1
a > b

Example

Click to collapse [-]
Server

This example shows a simple comparsion of two different strings.

local a = "Hello"
local b = "World"
local result = utf8.ncasecmp( a, b )

if result == -1 then
    print( "a < b" ) -- printed
elseif result == 0 then
    print( "a == b" )
elseif result == 1 then
    print( "a > b" )
end
Click to collapse [-]
Server

This example shows how to greet a player, when he write 'hello' into the chat.

addEventHandler("onPlayerChat", root,
    function (message, messageType)
        if messageType == 0 and utf8.ncasecmp( message, "hello" ) == 0 then
            outputChatBox( "* Server: Hello!", source, 255, 100, 100 )
        end
    end
)

See Also