RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • append
    • deblank
    • erase
    • eraseBetween
    • erasePunctuation
    • eraseURLs
    • extractAfter
    • extractBefore
    • extractBetween
    • insertAfter
    • insertBefore
    • join
    • lower
    • pad
    • replace
    • replaceBetween
    • reverse
    • split
    • splitlines
    • strcat
    • strip
    • strjoin
    • strjust
    • strrep
    • strsplit
    • strtrim
    • upper

strip — Remove leading and trailing characters from text inputs with MATLAB-compatible side and character-set options.

strip(text) removes leading/trailing whitespace by default across string, char, and cellstr-style inputs. Optional arguments control side selection ('left', 'right', 'both') and custom character sets, matching MATLAB semantics.

Syntax

out = strip(str)
out = strip(str, direction)
out = strip(str, stripCharacters)
out = strip(str, direction, stripCharacters)

Inputs

NameTypeRequiredDefaultDescription
strAnyYes—String/char/cell text input to strip.
directionStringScalarYes"both"Direction (`"left"|"right"|"both"`, plus leading/trailing synonyms).
stripCharactersAnyYes—Characters to strip (scalar or per-element text container).
directionStringScalarYes—Direction (`"left"|"right"|"both"`, plus leading/trailing synonyms).

Returns

NameTypeDescription
outAnyStripped text preserving input container kind and shape.

Errors

IdentifierWhenMessage
RunMat:strip:InvalidInputInput is not a string array, character array, or cell array of text scalars.strip: first argument must be a string array, character array, or cell array of character vectors
RunMat:strip:CellElementCell array contains a non-text element or non-row char array element.strip: cell array elements must be string scalars or character vectors
RunMat:strip:InvalidDirectionDirection argument is not one of left/right/both (or leading/trailing synonyms).strip: direction must be 'left', 'right', or 'both'
RunMat:strip:InvalidCharactersstripCharacters argument is not a valid text container.strip: characters to remove must be a string array, character vector, or cell array of character vectors
RunMat:strip:SizeMismatchPer-element stripCharacters does not match input shape/size.strip: stripCharacters must be the same size as the input when supplying multiple values
RunMat:strip:ArgCountMore than three input arguments were supplied.strip: too many input arguments
RunMat:strip:InternalErrorInternal output container construction failed.strip: internal error

How strip works

  • By default, strip removes leading and trailing whitespace determined by isspace.
  • Direction keywords are case-insensitive. 'left'/'leading' trim the beginning, 'right'/'trailing' trim the end, and 'both' removes characters on both sides.
  • Provide a second argument containing characters to remove to strip those characters instead of whitespace. Supply a scalar string/char vector to apply the same rule to every element or a string / cell array matching the input size to specify element-wise character sets.
  • Missing string scalars remain <missing>.
  • Character arrays shrink or retain their width to match the longest stripped row; shorter rows are padded with spaces so the output stays rectangular.
  • Cell arrays must contain string scalars or character vectors. Results preserve the original cell layout with trimmed elements.
  • Integer semantics: strip has no numeric input role. Numeric, logical, symbolic, and provider-resident values are rejected before gather or provider access.

Does RunMat run strip on the GPU?

strip executes on the CPU. When the input or any nested element resides on the GPU, RunMat gathers those values to host memory before trimming so the results match MATLAB exactly. Providers do not need to implement device kernels for this builtin today.

GPU memory and residency

Text data typically lives on the host. If you deliberately store text on the GPU (for example, by keeping character code points in device buffers), RunMat gathers them automatically when strip runs. You do not need to call gpuArray or gather manually for this builtin.

Examples

Remove Leading And Trailing Spaces From A String Scalar

name = "   RunMat   ";
clean = strip(name)

Expected output:

clean = "RunMat"

Trim Only The Right Side Of Each String

labels = ["   Alpha   "; "   Beta     "; "   Gamma    "];
right_stripped = strip(labels, 'right')

Expected output:

right_stripped = 3×1 string
    "   Alpha"
    "   Beta"
    "   Gamma"

Remove Leading Zeros While Preserving Trailing Digits

codes = ["00095"; "00137"; "00420"];
numeric = strip(codes, 'left', '0')

Expected output:

numeric = 3×1 string
    "95"
    "137"
    "420"

Strip Character Arrays And Preserve Rectangular Shape

animals = char("   cat  ", " dog", "cow   ");
trimmed = strip(animals)

Expected output:

trimmed =

  3×4 char array

    'cat '
    'dog '
    'cow '

Supply Per-Element Characters To Remove

metrics = ["##pass##", "--warn--", "**fail**"];
per_char = ["#"; "-"; "*"];
normalized = strip(metrics, 'both', per_char)

Expected output:

normalized = 3×1 string
    "pass"
    "warn"
    "fail"

Trim Cell Array Elements With Mixed Types

pieces = {'  GPU  ', "   Accelerate", 'RunMat   '};
out = strip(pieces)

Expected output:

out = 1×3 cell array
    {'GPU'}    {"Accelerate"}    {'RunMat'}

Using strip with coding agents

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

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

FAQ

Which direction keywords are supported?⌄

'left' and 'leading' trim the beginning of the text, 'right' and 'trailing' trim the end, and 'both' (the default) trims both sides.

How do I remove characters other than whitespace?⌄

Provide a second argument containing the characters to remove, for example strip(str, "xyz") removes any leading or trailing x, y, or z characters. Combine it with a direction argument to control which side is affected.

Can I specify different characters for each element?⌄

Yes. Pass a string array or cell array of character vectors that matches the size of the input. Each element is trimmed using the corresponding character set.

What happens to missing strings?⌄

Missing string scalars (string(missing)) remain <missing> exactly as in MATLAB.

Does strip change the shape of character arrays?⌄

Only the width can change. strip keeps the same number of rows and pads shorter rows with spaces so the array stays rectangular.

Will strip run on the GPU?⌄

Not currently. RunMat gathers GPU-resident inputs automatically and performs trimming on the CPU to maintain MATLAB compatibility.

Related Strings functions

Transform

append · deblank · erase · eraseBetween · erasePunctuation · eraseURLs · extractAfter · extractBefore · extractBetween · insertAfter · insertBefore · join · lower · pad · replace · replaceBetween · reverse · split · splitlines · strcat · strjoin · strjust · strrep · strsplit · strtrim · upper

Text Analytics

addDependencyDetails · addEntityDetails · addLemmaDetails · addPartOfSpeechDetails · addSentenceDetails · addTypeDetails · bagOfNgrams · bagOfWords · cosineSimilarity · doc2sequence · encode · extractFileText · extractHTMLText · fastTextWordEmbedding · findElement · getAttribute · htmlTree · ind2word · isVocabularyWord · normalizeWords · readWordEmbedding · removeLongWords · removeShortWords · removeStopWords · removeWords · stopWords · tokenDetails · tokenizedDocument · trainWordEmbedding · vaderSentimentScores · vec2word · word2ind · word2vec · wordEncoding · writeWordEmbedding

Core

blanks · char · compose · convertCharsToStrings · convertContainedStringsToChars · convertStringsToChars · genvarname · int2str · isletter · isspace · isStringScalar · isstrprop · mat2str · native2unicode · newline · num2str · sprintf · sscanf · str2double · str2num · strcmp · strcmpi · string · string.empty · strings · strlength · strncmp · strncmpi · strtok · unicode2native

Search

contains · endsWith · matches · startsWith · strfind

Pattern

digitsPattern · lettersPattern · pattern · regexpPattern · textBoundary · wildcardPattern

Regex

regexp · regexpi · regexprep

Open-source implementation

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

  • View the source for strip in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

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.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How strip works
  • Does RunMat run strip on the GPU?
  • GPU memory and residency
  • Examples
  • Remove Leading And Trailing Spaces From A String Scalar
  • Trim Only The Right Side Of Each String
  • Remove Leading Zeros While Preserving Trailing Digits
  • Strip Character Arrays And Preserve Rectangular Shape
  • Supply Per-Element Characters To Remove
  • Trim Cell Array Elements With Mixed Types
  • Using strip with coding agents
  • FAQ
  • Related Strings functions
  • Transform
  • Text Analytics
  • Core
  • Search
  • Pattern
  • Regex
  • Open-source implementation
  • About RunMat