Block reference / Data

Slice variable

Keep part of a variable's text or list, by position.

In both appsWarpX BrowserWarpX Phone

Slice variable cuts a variable down to a range of positions: characters of a text, or items of a list. The variable is overwritten with the part you keep. Use it to strip a fixed prefix or keep the first few results.

The Slice variable block's settings, filled in as in the example below.

Settings

Variable name

The variable to cut. It is replaced with the slice.

ExampleorderRef
Start index

Tick Start index and type the position to start from. Positions count from 0, and a negative number counts back from the end. It is ticked by default.

Example9
End index

Tick End index and type the position to stop before. That position is not included. Left unticked, the slice runs to the end.

Example14

Every block also has the shared block settings — a description, Disable block and what to do on an error. Fields that take text accept data from earlier blocks.

What it hands on

Overwrites the variable with the slice and hands the slice on as {{prevBlockData}}.

Example: Keep only the number in an order reference

  1. Start
  2. Open URL
  3. Get text
  4. Slice variable
  5. Insert data
Where Slice variable sits in the example workflow.
  1. Read ORD-2026-58213-VN into a variable with Get text and Assign to variable, named orderRef.
  2. Add Slice variable and type orderRef in Variable name.
  3. Tick Start index and type 9. Tick End index and type 14.
  4. Run it. orderRef is now 58213.

Good to know

  • If the variable does not exist, or holds something that cannot be sliced such as a number, the block changes nothing and raises no error.
  • A value inserted as 58213 is stored as a number, not text, and is then left as it is.
  • The indexes are plain numbers. References are not filled in there, nor in the variable name.
  • For a variable whose name starts with $$, only this run's copy changes.

See also

  • RegEx variable — Replace a text variable with what a regular expression matches, or with a replaced version.
  • Increase variable — Add a number to a variable, such as a counter.
  • Insert data — Set variables and add values to the workflow's table, several at once.