Skip to content

API len en

Codex edited this page Oct 3, 2026 · 1 revision

len

API · BASIC

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

ASC · Chr · len · StrComp

ClassicUO • Runtime API

Checks text length for validation and labels, or the length of a number’s textual representation.

Exact syntax

len(value:Decimal) -> Integer
len(value:Integer) -> Integer
len(value:String) -> Integer

Parameters

  • value — String, Integer or Decimal. Numbers are formatted with invariant culture before counting; the minus sign and decimal point count too.

Returns

Integer count of UTF-16 code units. Empty text returns 0. An emoji can count as 2; combining marks also count separately. Numeric Len is text length, not the number’s storage size. Use GetArrayLength for an Array.

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.
  • No bytes, pixels, visible glyphs or nested array elements are counted. Text slicing by this count can split a surrogate pair; the abbreviation example deliberately uses ASCII names.

Internal functions: from call to result

The String overload reads Length. Integer and Decimal overloads format with invariant culture, then read Length. No conversion or truncation of the original value occurs.

1. InternalSubrutines.Len

The String overload reads Length. Integer and Decimal overloads format with invariant culture, then read Length. No conversion or truncation of the original value occurs.

Integer count of UTF-16 code units. Empty text returns 0. An emoji can count as 2; combining marks also count separately. Numeric Len is text length, not the number’s storage size. Use GetArrayLength for an Array.

Project source: external/InjectionScript/src/InjectionScript/Runtime/InternalSubrutines.cs; function InternalSubrutines.Len.

No bytes, pixels, visible glyphs or nested array elements are counted. Text slicing by this count can split a surrogate pair; the abbreviation example deliberately uses ASCII names.

Examples

Shorten a label

# Shorten a label
#
# Checks text length for validation and labels, or the length of a number’s textual
# representation.
#
# Integer count of UTF-16 code units. Empty text returns 0. An emoji can count as 2; combining
# marks also count separately. Numeric Len is text length, not the number’s storage size. Use
# GetArrayLength for an Array.

SUB Main()
    # LongCharacterName exceeds 8 units. Taking five ASCII letters plus three dots returns LongC...,
    # exactly 8 units.
    # 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 label = "LongCharacterName"
    If Len(label) > 8 Then
        Return Left(label, 5) & "..."
    End If
    Return label
END SUB

Parameter and execution notes:

  • LongCharacterName exceeds 8 units. Taking five ASCII letters plus three dots returns LongC..., exactly 8 units.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Reject an empty setting

# Reject an empty setting
#
# Checks text length for validation and labels, or the length of a number’s textual
# representation.
#
# Integer count of UTF-16 code units. Empty text returns 0. An emoji can count as 2; combining
# marks also count separately. Numeric Len is text length, not the number’s storage size. Use
# GetArrayLength for an Array.

SUB Main()
    # Trim removes the sample spaces. Len returns 0, so Main returns missing; a nonempty setting
    # would be returned unchanged.
    # 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 setting = Trim("   ")
    If Len(setting) = 0 Then
        Return "missing"
    End If
    Return setting
END SUB

Parameter and execution notes:

  • Trim removes the sample spaces. Len returns 0, so Main returns missing; a nonempty setting would be returned unchanged.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Distinguish character and numeric lengths

# Distinguish character and numeric lengths
#
# Checks text length for validation and labels, or the length of a number’s textual
# representation.
#
# Integer count of UTF-16 code units. Empty text returns 0. An emoji can count as 2; combining
# marks also count separately. Numeric Len is text length, not the number’s storage size. Use
# GetArrayLength for an Array.

SUB Main()
    # The emoji has length 2. -125 formats as four characters, including the sign. Main returns 2|4,
    # not a byte count.
    # 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 = Chr(0x1F600)
    Dim quantity = -125
    Return CStr(Len(symbol)) & "|" & CStr(Len(quantity))
END SUB

Parameter and execution notes:

  • The emoji has length 2. -125 formats as four characters, including the sign. Main returns 2|4, not a byte count.
  • 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