Skip to content

toArray

ffredyk edited this page Jul 23, 2026 · 1 revision

toArray

Category

String

Arity

UnarytoArray <string>.

toArray <string>

Description

Converts a string to an array of character codes (ASCII/Unicode code points as integers). Each character becomes one integer element in the result array. Empty string → empty array.

How It Works

Iterates each char in the string, casts to int, and collects into a new array. For characters above U+FFFF (surrogate pairs), each surrogate half is a separate element.

Usage

Basic conversion

toArray "AB";                  // [65, 66]
toArray "Hello";               // [72, 101, 108, 108, 111]
toArray "";                    // []

Character-by-character processing

_codes = toArray _name;
_codes forEach {
    systemChat f"Char code: {_x}";
};

Case checking via codes

_codes = toArray _name;
_firstCode = _codes select 0;
_isUpper = _firstCode >= 65 && _firstCode <= 90;

Round-trip with toString

_original = "Test";
_codes = toArray _original;
_restored = toString _codes;   // "Test"
_original == _restored;        // true

Thread Safety

ReadOnly — pure computation, returns new array. Safe from any scheduler.

See Also

  • toString — reverse: array of codes to string
  • count — string length
  • select — character at index

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally