Skip to content

splitString

ffredyk edited this page Jul 23, 2026 · 1 revision

splitString

Category

String

Arity

Binary<string> splitString <separator>. Also accepts array form: splitString [string, separator].

<string> splitString <string>
splitString <array>   // [string, separator]

Description

Splits a string by the given separator into an array of substrings. Returns the array. If the separator is not found, returns an array with the original string as the single element.

How It Works

Calls string.Split(separator, StringSplitOptions.None) with ordinal comparison. Empty strings between consecutive separators are preserved (unlike StringSplitOptions.RemoveEmptyEntries).

Usage

Basic split

"a,b,c" splitString ",";       // ["a", "b", "c"]
splitString ["a,b,c", ","];    // same, array form

CSV parsing

_line = "John,Doe,42,Engineer";
_fields = _line splitString ",";
_name = _fields select 0;      // "John"
_age = parseNumber (_fields select 2);  // 42

Path splitting

_path = "scripts\ai\combat.sqf";
_parts = _path splitString "\";
_filename = _parts select (count _parts - 1);  // "combat.sqf"

Multi-character separator

_data = "key=value;name=test;hp=100";
_pairs = _data splitString ";";
_pairs forEach {
    _kv = _x splitString "=";
    systemChat f"{_kv select 0} -> {_kv select 1}";
};

Word splitting

_words = "the quick brown fox" splitString " ";
count _words;                  // 4

Thread Safety

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

See Also

  • joinString — reverse: join array into string
  • find — find substring position
  • in — substring check
  • select — access characters

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