Skip to content

toString

ffredyk edited this page Jul 23, 2026 · 1 revision

toString

Category

String

Arity

UnarytoString <array>.

toString <array>   // array of character codes (integers)

Description

Converts an array of character codes (integers) into a string. Each integer is interpreted as a Unicode code point. This is the reverse of toArray.

How It Works

Iterates the array, casts each integer to char, and builds a new string. Non-integer values or values outside the valid char range may produce unexpected characters.

Usage

Basic conversion

toString [65, 66];             // "AB"
toString [72, 101, 108, 108, 111];  // "Hello"
toString [];                   // "" (empty string)

Building strings from codes

_newline = toString [10];      // line feed
_tab = toString [9];           // tab
_space = toString [32];        // space

Round-trip with toArray

_original = "SQF";
_codes = toArray _original;    // [83, 81, 70]
_restored = toString _codes;   // "SQF"

Dynamic character generation

// Generate "ABC...Z"
_letters = [];
for "_i" from 65 to 90 do {
    _letters pushBack _i;
};
_alphabet = toString _letters;  // "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Simple obfuscation / encoding

_encode = {
    params ["_str"];
    _codes = toArray _str;
    _shifted = [];
    { _shifted pushBack (_x + 1) } forEach _codes;
    toString _shifted
};
_encoded = "hello" call _encode;  // "ifmmp"

Thread Safety

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

See Also

  • toArray — reverse: string to code array
  • str — general value to string
  • format — formatted string output

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