Utf8.ncasecmp

From Multi Theft Auto: Wiki
Revision as of 15:40, 15 February 2016 by Necktrox (talk | contribs) (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 )...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Compares two strings in lower-case and returns the difference as a number value.

Syntax

int utf8.ncasecmp ( string a, string b )

Required Arguments

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

Returns

Returns a number, 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