util.string.ncasecmp

Shared

Compares two strings case-insensitively across full Unicode case folding


Syntax

local result = util.string.ncasecmp(
    a,
    b
)

Parameters

TypeNameDescription
stringaFirst string to compare
stringbSecond string to compare

Returns

TypeNameDescription
intresult-1 if a < b - 0 if equal - 1 if a > b (after case folding)

Examples

Compare two strings that only differ by case
local result = util.string.ncasecmp("Hello", "HELLO")

core.engine.print("info", result) -- 0
Compare two genuinely different strings
local result = util.string.ncasecmp("Apple", "Banana")

core.engine.print("info", result) -- -1
Use as a case-insensitive equality check
if util.string.ncasecmp("YES", "yes") == 0 then
    core.engine.print("info", "Strings match, ignoring case")
end
Sort a table of strings case-insensitively
local words = {"banana", "Apple", "cherry"}

util.table.sort(words, function(a, b)
    return util.string.ncasecmp(a, b) < 0
end)

core.engine.print("info", util.table.concat(words, ", ")) -- 'Apple, banana, cherry'

On this page