RunMat
GitHub

split — Split text values into substrings using delimiter rules with MATLAB-compatible container behavior.

split(text) breaks text into substrings separated by delimiters across string, char, and cell-text inputs. It follows MATLAB-compatible default-delimiter and output-container behavior, including whitespace splitting when no delimiter is provided.

Syntax

newStr = split(str)
newStr = split(str, delimiter)
newStr = split(str, delimiter, Name, Value, ...)
newStr = split(str, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
strAnyYesInput text scalar/array/cell to split.
delimiterAnyYesDelimiter scalar/array/cell.
NameStringScalarYesOption name (`CollapseDelimiters` or `IncludeDelimiters`).
ValueAnyVariadicOption values and additional Name/Value pairs.

Returns

NameTypeDescription
newStrAnyString array containing split tokens.

Errors

IdentifierWhenMessage
RunMat:split:InvalidInputFirst argument is not a string scalar/array, char array, or cell array of text scalars.split: first argument must be a string scalar, string array, character array, or cell array of character vectors
RunMat:split:DelimiterTypeDelimiter input is not a supported text scalar/array/cell.split: delimiter input must be a string scalar, string array, character array, or cell array of character vectors
RunMat:split:NameValuePairName-value options are not supplied in complete pairs.split: name-value arguments must be supplied in pairs

How split works

  • The default delimiter is whitespace (isspace), and consecutive whitespace is treated as a single separator (equivalent to 'CollapseDelimiters', true).
  • When you supply explicit delimiters, they can be a string scalar, string array, character array (rows), or a cell array of character vectors. Delimiters are matched left to right and the longest delimiter wins when several candidates match at the same position.
  • 'CollapseDelimiters' controls whether consecutive delimiters generate empty substrings. The default is false when you specify explicit delimiters and true when you rely on the whitespace default.
  • 'IncludeDelimiters' inserts the matched delimiters as separate elements in the output string array.
  • Outputs are string arrays. For scalar inputs, the result is a row vector. For string/character arrays, the first dimension matches the number of rows in the input and additional columns are appended to accommodate the longest token list. Missing values are padded with <missing>.
  • Missing string scalars propagate unchanged.

Does RunMat run split on the GPU?

split executes on the CPU. When the input or delimiter arguments reside on the GPU, RunMat gathers them to host memory before performing the split so the results match MATLAB exactly. Providers do not need to implement custom kernels for this builtin today.

GPU memory and residency

String manipulation currently runs on the host. If text data lives on the GPU (for example after a gathered computation), split automatically fetches it. You never need to move text explicitly before calling this builtin.

Examples

Split A String On Whitespace

txt = "RunMat Accelerate Planner";
pieces = split(txt)

Expected output:

pieces = 1×3 string
    "RunMat"    "Accelerate"    "Planner"

Split A String Using A Custom Delimiter

csv = "alpha,beta,gamma";
tokens = split(csv, ",")

Expected output:

tokens = 1×3 string
    "alpha"    "beta"    "gamma"

Include Delimiters In The Output

expr = "A+B-C";
segments = split(expr, ["+", "-"], "IncludeDelimiters", true)

Expected output:

segments = 1×5 string
    "A"    "+"    "B"    "-"    "C"

Preserve Empty Segments When CollapseDelimiters Is False

values = "one,,three,";
parts = split(values, ",", "CollapseDelimiters", false)

Expected output:

parts = 1×4 string
    "one"    ""    "three"    ""

Split Each Row Of A Character Array

rows = char("GPU Accelerate", "VM Interpreter");
result = split(rows)

Expected output:

result = 2×2 string
    "GPU"          "Accelerate"
    "VM"           "Interpreter"

Split Elements Of A Cell Array

C = {'RunMat Snapshot'; "Fusion Planner"};
out = split(C, " ")

Expected output:

out = 2×2 string
    "RunMat"    "Snapshot"
    "Fusion"    "Planner"

Handle Missing String Inputs

names = ["RunMat", "<missing>", "Accelerate Engine"];
split_names = split(names)

Expected output:

split_names = 3×2 string
    "RunMat"        "<missing>"
    "<missing>"     "<missing>"
    "Accelerate"    "Engine"

Using split with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how split changes the result.

Run a small split example, explain the result, then change one input and compare the output.

FAQ

What delimiters does split use by default?

When you omit the second argument, split treats any Unicode whitespace as a delimiter and collapses consecutive whitespace runs so they produce a single split point.

How do explicit delimiters change the defaults?

Providing explicit delimiters switches the default for 'CollapseDelimiters' to false, matching MATLAB. You can override that behaviour with a name-value pair.

What happens when 'IncludeDelimiters' is true?

Matched delimiters are inserted between tokens in the output string array, preserving their original order. Tokens still expand to fill rows and columns, with missing values used for padding.

How is the output sized for string arrays?

The number of rows matches the input. Columns are added to accommodate the longest token list observed across all elements. Shorter rows are padded with <missing>.

How does split handle missing strings?

Missing string scalars propagate unchanged. When padding is required, <missing> is used so MATLAB and RunMat stay aligned.

Can I provide empty delimiters?

No. Empty delimiters are disallowed, matching MATLAB's input validation. Specify at least one character per delimiter.

Which argument types are accepted as delimiters?

You may pass string scalars, string arrays, character arrays (each row is a delimiter), or cell arrays containing string scalars or character vectors.

How is split different from strsplit?

split is the vectorized string-focused builtin in RunMat. Use strsplit when you need the MATLAB-style scalar-text API with optional matches output and DelimiterType handling.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how split is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.