strip — Remove leading and trailing characters from text with side and character-set controls.
strip(text) trims whitespace by default; optional direction and stripCharacters controls select a side and custom character set for supported text containers.
Syntax
out = strip(str)
out = strip(str, direction)
out = strip(str, stripCharacters)
out = strip(str, direction, stripCharacters)Inputs
str- Type
Any- Required
- Yes
- Description
- String, character, or cell text input.
direction- Type
StringScalar- Required
- Yes
- Default
"both"- Description
- Side to strip: left, right, or both; RunMat also accepts leading and trailing.
stripCharacters- Type
Any- Required
- Yes
- Description
- Scalar or shape-matched characters to remove.
Returns
out- Type
Any- Description
- Stripped text preserving input container kind and shape.
Errors
RunMat:strip:InvalidInput- When
- Input is not a string array, character array, or cell array of text scalars.
- Message
strip: first argument must be a string array, character array, or cell array of character vectors
RunMat:strip:CellElement- When
- Cell array contains a non-text or non-row character element.
- Message
strip: cell array elements must be string scalars or character vectors
RunMat:strip:InvalidDirection- When
- Direction is not left/right/both or an accepted synonym.
- Message
strip: direction must be 'left', 'right', or 'both'
Text and controls
strip(text) removes leading and trailing whitespace by default. Direction is case-insensitive: 'left' removes from the beginning, 'right' from the end, and 'both' from both sides. RunMat extension mode also accepts 'leading' and 'trailing' as aliases.
Supply a scalar stripCharacters value to remove a custom character instead of whitespace. RunMat extension mode also accepts multi-character sets and shape-matched string or cell arrays of per-element sets.
String scalars and arrays preserve their shape and typed missing elements. Character arrays are stripped row by row; the row count stays fixed and shorter rows are space-padded to the longest resulting width. Cell arrays preserve their layout and contain string scalars or character vectors.
Placement and errors
strip is a host text operation and is a fusion boundary. Numeric, logical, symbolic, and provider-resident inputs are not interpreted as characters and reject before provider access. A textual control or nested cell cannot make a numeric or resident value into a supported text input.
Invalid direction, strip-character type, per-element shape, or cell element raises a typed error. The operation has no provider kernel, callbacks, or external resource dependency.
Examples
Remove surrounding spaces
name = " RunMat ";
clean = strip(name)Expected output:
clean = "RunMat"Strip only the right side
labels = [" Alpha "; " Beta "; " Gamma "];
right_stripped = strip(labels, 'right')Expected output:
right_stripped = [" Alpha"; " Beta"; " Gamma"]Remove leading zeroes
codes = ["00095"; "00137"; "00420"];
numeric = strip(codes, 'left', '0')Expected output:
numeric = ["95"; "137"; "420"]Keep character rows rectangular
animals = char(" cat ", " dog", "cow ");
trimmed = strip(animals)Expected output:
trimmed = ['cat'; 'dog'; 'cow']Use one character set per element
metrics = ["##pass##"; "--warn--"; "**fail**"];
per_char = ["#"; "-"; "*"];
normalized = strip(metrics, 'both', per_char)Expected output:
normalized = ["pass"; "warn"; "fail"]Strip a mixed text cell
pieces = {' GPU ', " Accelerate", 'RunMat '};
out = strip(pieces)Expected output:
out = {'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', 'right', and 'both' are the standard directions. RunMat extension mode also accepts 'leading' and 'trailing'. Matching is case-insensitive.
How can I remove characters other than whitespace?⌄
Pass one strip character in the standard mode, for example strip(text, 'x'). RunMat extension mode also accepts a set such as 'xyz'; every matching character is then removed from the chosen edge.
Can each element use different strip characters?⌄
In RunMat extension mode, a string or cell character-set array can match the input shape; each element then uses its corresponding set.
What happens to missing strings?⌄
Typed missing subject elements remain missing. Literal <missing> text is ordinary text; missing direction or character controls are rejected.
Does strip change character-array shape?⌄
Only width may change. Rows are stripped independently and padded to the longest resulting row.
Does strip execute on the GPU?⌄
No. It operates on host text; provider-resident numeric values are not automatically reinterpreted as text.
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
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.