Skip to content

API StrComp en

Codex edited this page Oct 3, 2026 · 1 revision

StrComp

API · BASIC

Русский · English · Українська · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

ASC · Chr · len · StrComp

ClassicUO • Runtime API

Compares names or command text when exact equality and a stable ordering are needed.

Exact syntax

StrComp(left:String, right:String) -> Integer

Parameters

  • left — Left String to compare.
  • right — Right String to compare. Both parameters are required; there is no third comparison-mode parameter.

Returns

Integer -1 if left sorts before right, 0 if equal, or 1 if after, using case-sensitive ordinal UTF-16 comparison. This is not Boolean: equality means result = 0. A plain If StrComp(...) is true for unequal strings.

Behavior

  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.
  • Comparison is independent of the interface language and does not perform natural-language sorting or case folding. If your rule ignores case, normalize explicitly with LCase or UCase. Neither input is changed.

Internal functions: from call to result

BasicStrComp performs String.Compare with Ordinal, then Math.Sign reduces the result to -1, 0 or 1.

1. BasicStrComp / String.Compare / Math.Sign

BasicStrComp performs String.Compare with Ordinal, then Math.Sign reduces the result to -1, 0 or 1.

Integer -1 if left sorts before right, 0 if equal, or 1 if after, using case-sensitive ordinal UTF-16 comparison. This is not Boolean: equality means result = 0. A plain If StrComp(...) is true for unequal strings.

Project source: external/InjectionScript/src/InjectionScript/Runtime/InjectionApi.cs; function BasicStrComp / String.Compare / Math.Sign.

Comparison is independent of the interface language and does not perform natural-language sorting or case folding. If your rule ignores case, normalize explicitly with LCase or UCase. Neither input is changed.

Examples

Recognize a normalized command

# Recognize a normalized command
#
# Compares names or command text when exact equality and a stable ordering are needed.
#
# Integer -1 if left sorts before right, 0 if equal, or 1 if after, using case-sensitive ordinal
# UTF-16 comparison. This is not Boolean: equality means result = 0. A plain If StrComp(...) is
# true for unequal strings.

SUB Main()
    # Trim and LCase turn " STOP " into stop. Explicit equality to 0 returns True (1). This checks
    # the text; it does not stop any running script.
    # Runs locally. Examples process sample data and return a value; they do not send chat, stop a
    # script, move items or contact the server.

    Dim action = LCase(Trim(" STOP "))
    If StrComp(action, "stop") = 0 Then
        Return True
    End If
    Return False
END SUB

Parameter and execution notes:

  • Trim and LCase turn " STOP " into stop. Explicit equality to 0 returns True (1). This checks the text; it does not stop any running script.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Order two resource names

# Order two resource names
#
# Compares names or command text when exact equality and a stable ordering are needed.
#
# Integer -1 if left sorts before right, 0 if equal, or 1 if after, using case-sensitive ordinal
# UTF-16 comparison. This is not Boolean: equality means result = 0. A plain If StrComp(...) is
# true for unequal strings.

SUB Main()
    # zinc compares after iron, so local variables are swapped. Main returns iron|zinc; this is
    # ordinal order, not a full inventory sort.
    # Runs locally. Examples process sample data and return a value; they do not send chat, stop a
    # script, move items or contact the server.

    Dim first = "zinc"
    Dim second = "iron"
    If StrComp(first, second) > 0 Then
        Dim saved = first
        first = second
        second = saved
    End If
    Return first & "|" & second
END SUB

Parameter and execution notes:

  • zinc compares after iron, so local variables are swapped. Main returns iron|zinc; this is ordinal order, not a full inventory sort.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Find an exact allowed name

# Find an exact allowed name
#
# Compares names or command text when exact equality and a stable ordering are needed.
#
# Integer -1 if left sorts before right, 0 if equal, or 1 if after, using case-sensitive ordinal
# UTF-16 comparison. This is not Boolean: equality means result = 0. A plain If StrComp(...) is
# true for unequal strings.

SUB Main()
    # ContainsExact splits the sample list with | and compares each name to Ore. It returns True (1)
    # only on exact equality; ore alone would not match Ore.
    # Runs locally. Examples process sample data and return a value; they do not send chat, stop a
    # script, move items or contact the server.

    Return ContainsExact("ore|Ore|wood", "Ore")
END SUB

Function ContainsExact(names, wanted)
    For index = 0 To GetWordCount(names, "|") - 1
        If StrComp(GetWord(names, index, "|"), wanted) = 0 Then
            Return True
        End If
    Next
    Return False
End Function

Parameter and execution notes:

  • ContainsExact splits the sample list with | and compares each name to Ore. It returns True (1) only on exact equality; ore alone would not match Ore.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Clone this wiki locally