Skip to content
ffredyk edited this page Jul 23, 2026 · 1 revision

format

Category

String

Arity

Unaryformat [template, arg1, arg2, ...].

format <array>   // [template, arg1, arg2, ...]

Description

Formats a string using %1, %2, ... placeholders replaced by the corresponding arguments. The right operand is an array where the first element is the template string, followed by substitution values. This matches Arma SQF format behavior.

How It Works

Parses the template string for %N tokens (where N is a 1-based index). Each token is replaced with str of the corresponding argument from the array. Arguments beyond the template are ignored. Missing placeholders remain unchanged.

Usage

Basic formatting

_result = format ["HP: %1/%2", _hp, _maxHp];  // "HP: 75/100"

Named-style output

_msg = format ["%1 killed %2 with %3", _killer, _victim, _weapon];

Debug messages

diag_log format ["Frame %1: %2 units, %3 FPS", _frame, count _units, _fps];

Coordinates / vectors

_posStr = format ["[%1, %2, %3]", _x, _y, _z];

Multi-line

_report = format ["Name: %1\nScore: %2\nRank: %3", _name, _score, _rank];

vs f-strings

SQ# also supports f-strings (compile-time):

// format (runtime)
_msg = format ["Hello %1", _name];

// f-string (compile-time, preferred when possible)
_msg = f"Hello {_name}";

Prefer f-strings when the template is known at compile time. Use format when the template is dynamic (loaded from config, user input, etc.).

Thread Safety

ReadOnly — pure computation, no side effects. Safe from any scheduler.

See Also

  • str — simple value to string
  • + — string concatenation
  • parseNumber — parse number from string

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