-
Notifications
You must be signed in to change notification settings - Fork 0
Strings
ffredyk edited this page Jul 23, 2026
·
1 revision
SQ# strings are immutable .NET strings with modern enhancements: escape sequences, verbatim strings, multi-line literals, interpolation, and a rich set of string commands.
_name = "Hello\nWorld"; // \n = newline
_tab = "Col1\tCol2"; // \t = tab
_quote = "He said \"Hi\""; // \" = escaped quote
_path = "C:\\Users\\Name"; // \\ = backslash
_unicode = "\u00A9"; // © (Unicode escape)Supported escapes: \n, \r, \t, \\, \", \', \uXXXX
_path = 'C:\Users\Name'; // backslashes are literal
_quote = 'It\'s fine'; // only ' needs escaping_path = @"C:\Users\Name\Documents"; // NO escapes at all
_regex = @"\d+\.\d+"; // great for regex patterns_help = """
Usage: mycommand [options]
Options:
-h, --help Show this message
-v, --verbose Enable verbose output
""";Leading/trailing whitespace on the first/last line is trimmed.
_name = "Fred";
_hp = 75;
_maxHp = 100;
// Basic interpolation
_msg = f"Player {_name} has {_hp} HP";
// Expressions in braces
_msg = f"HP: {_hp}/{_maxHp} ({_hp / _maxHp * 100}%)";
// Multi-line interpolation
_report = f"""
Name: {_name}
HP: {_hp}/{_maxHp}
Status: {if (_hp > 50) then {"Healthy"} else {"Wounded"}}
""";f-strings are compile-time — the template is parsed and compiled once. Prefer f-strings over format when the template is known at compile time.
Use when the template is dynamic (loaded from config, user input):
// %1, %2, ... placeholders
_result = format ["HP: %1/%2", _hp, _maxHp]; // "HP: 75/100"
// Dynamic template
_template = loadConfig("messageTemplate");
_msg = format [_template, _name, _score];| Command | Description | Example |
|---|---|---|
count |
String length |
count "hello" → 5
|
select |
Character at index |
"hello" select 1 → "e"
|
find |
Substring index (-1 if not found) |
"hello" find "ll" → 2
|
in |
Contains check |
"ell" in "hello" → true
|
+ |
Concatenation |
"Hello " + "World" → "Hello World"
|
str |
Any → string |
str 42 → "42"
|
format |
sprintf-style | format ["%1 %2", "a", "b"] |
parseNumber |
String → number (nil on fail) |
parseNumber "123" → 123
|
toArray |
String → code point array |
toArray "AB" → [65, 66]
|
toString |
Code points → string |
toString [65, 66] → "AB"
|
splitString |
Split by separator |
"a,b,c" splitString "," → ["a","b","c"]
|
joinString |
Join with separator |
joinString [["a","b"], "-"] → "a-b"
|
toLower |
Lowercase |
toLower "HELLO" → "hello"
|
toUpper |
Uppercase |
toUpper "hello" → "HELLO"
|
trim |
Remove whitespace |
trim " hi " → "hi"
|
_equalsIgnoreCase = {
params ["_a", "_b"];
toLower _a == toLower _b
};_line = "John,Doe,42,Engineer";
_fields = _line splitString ",";
_name = _fields select 0; // "John"
_age = parseNumber (_fields select 2); // 42_path = "scripts\ai\combat.sqf";
_parts = _path splitString "\";
_filename = _parts select (count _parts - 1); // "combat.sqf"
_dir = joinString [_parts select [0, count _parts - 1], "\"];_name = trim _userInput;
if (_name == "") then {
print "Name cannot be empty";
};
_isNumeric = !isNil parseNumber _input;// SLOW — each + creates new string (1000 allocations):
_msg = "";
for "_i" from 0 to 999 do { _msg = _msg + "x"; };
// FAST — build array, join once (1 allocation):
_parts = [];
for "_i" from 0 to 999 do { _parts pushBack "x"; };
_msg = joinString [_parts, ""];- str — value to string
- format — sprintf-style formatting
- splitString — split string
- joinString — join array into string
- parseNumber — parse number from string
- Language Guide — string literal syntax
- Getting Started
- Language Guide
- Type System
- Control Flow
- Functions & Code
- Strings & Text
- Arrays & Collections
- Concurrency
- Promise System
- Thread Safety
- Host API & Embedding
- CLI Tool
- Bytecode Reference
- Multiplayer
- Syntax Sugar
- Optimization Guide
- Benchmarks
- count
- select
- pushBack
- append
- deleteAt
- deleteRange
- resize
- reverse
- sort
- find
- in
- forEach
- freeze
- thaw
- isFrozen
- currentScheduler
- clientOwner
- allSchedulers
- schedulerName
- schedulerExists
- schedulerBudget
- setSchedulerBudget
- fiberCount
- readyFiberCount
- waitingFiberCount
- schedulerLoad
- sendTo