Skip to content

API Chr en

Codex edited this page Oct 3, 2026 · 1 revision

Chr

API · BASIC

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

ASC · Chr · len · StrComp

ClassicUO • Runtime API

Creates a Unicode character or a control character for composing text.

Exact syntax

Chr(value:Integer) -> String

Parameters

  • value — Integer Unicode scalar code. Values below 0 clamp to 0; values above 0x10FFFF clamp to 0x10FFFF. Surrogates 0xD800..0xDFFF cause a catchable error.

Returns

String of one or two UTF-16 code units. Chr(0) contains a NUL character, not an empty string. Chr(0x1F600) occupies two units; ASC of that result does not recover its full scalar code.

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.
  • Use Integer codes; this typed overload does not accept a Decimal code directly. Tabs and line breaks are text characters, not keyboard actions. How a displayed control character appears depends on the destination widget.

Internal functions: from call to result

BasicChr clamps the Integer code and calls ConvertFromUtf32. The conversion rejects surrogate codes and produces a surrogate pair for a valid scalar above 0xFFFF.

1. BasicChr / Char.ConvertFromUtf32

BasicChr clamps the Integer code and calls ConvertFromUtf32. The conversion rejects surrogate codes and produces a surrogate pair for a valid scalar above 0xFFFF.

String of one or two UTF-16 code units. Chr(0) contains a NUL character, not an empty string. Chr(0x1F600) occupies two units; ASC of that result does not recover its full scalar code.

Project source: external/InjectionScript/src/InjectionScript/Runtime/InjectionApi.cs; function BasicChr / Char.ConvertFromUtf32.

Use Integer codes; this typed overload does not accept a Decimal code directly. Tabs and line breaks are text characters, not keyboard actions. How a displayed control character appears depends on the destination widget.

Examples

Prepare a tab-separated record

# Prepare a tab-separated record
#
# Creates a Unicode character or a control character for composing text.
#
# String of one or two UTF-16 code units. Chr(0) contains a NUL character, not an empty string.
# Chr(0x1F600) occupies two units; ASC of that result does not recover its full scalar code.

SUB Main()
    # Chr(9) inserts one tab between ore and 50. Main returns the text ore<TAB>50 for later file or
    # message use.
    # 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 resource = "ore"
    Dim amount = 50
    Return resource & Chr(9) & CStr(amount)
END SUB

Parameter and execution notes:

  • Chr(9) inserts one tab between ore and 50. Main returns the text ore50 for later file or message use.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Prepare two lines

# Prepare two lines
#
# Creates a Unicode character or a control character for composing text.
#
# String of one or two UTF-16 code units. Chr(0) contains a NUL character, not an empty string.
# Chr(0x1F600) occupies two units; ASC of that result does not recover its full scalar code.

SUB Main()
    # Chr(13) and Chr(10) build CRLF between First and Second. The example composes text without
    # sending it.
    # 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 summary = "First" & Chr(13) & Chr(10) & "Second"
    Return summary
END SUB

Parameter and execution notes:

  • Chr(13) and Chr(10) build CRLF between First and Second. The example composes text without sending it.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Handle an invalid character

# Handle an invalid character
#
# Creates a Unicode character or a control character for composing text.
#
# String of one or two UTF-16 code units. Chr(0) contains a NUL character, not an empty string.
# Chr(0x1F600) occupies two units; ASC of that result does not recover its full scalar code.

SUB Main()
    # SafeCharacter catches invalid surrogate codes and returns empty text on error. With 0x1F600 it
    # succeeds; Len returns 2 UTF-16 units, although this is one Unicode scalar.
    # 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 symbol = SafeCharacter(0x1F600)
    Return Len(symbol)
END SUB

Function SafeCharacter(code)
    Try
        Return Chr(code)
    Catch problem
        Return ""
    End Try
End Function

Parameter and execution notes:

  • SafeCharacter catches invalid surrogate codes and returns empty text on error. With 0x1F600 it succeeds; Len returns 2 UTF-16 units, although this is one Unicode scalar.
  • 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