Skip to content

Slice

Name Mandatory Description Default Type
⬅️ Input The string or sequence from which characters/elements have to be extracted. [Any]BytesString
Output ➡️ The extracted characters/elements. Any
From No The position/index of the first character or element that is to be extracted (including). Negative position/indices simply loop over the target string/sequence counting backwards. 0 Int[Int]Var(Int)Var([Int])
To No The position/index of the last character or element that is to be extracted (excluding). Negative position/indices simply loop over the target string/sequence counting backwards. none Int[Int]Var(Int)Var([Int])None
Step No The increment between each position/index. Chooses every nth sample to extract, where n is the increment. Value has to be greater than zero. 1 Int

Extracts characters from a string or elements from a sequence based on the start and end positions/indices and an increment parameter. Operation is non-destructive; the target string/sequence is not modified.

Examples

1
2
3
4
5
6
7
8
; Slice on strings
"Hello World" | Slice(From: 1 To: 3 Step: 1) | Log ; => "el"
"Hello World" | Slice(0 11 2) | Log ; => "HloWrd"

; Slice on sequences
[10 20 30 40 50 60 70 80 90] | Slice(1 3 1) | Log ; => [20, 30]
[10 20 30 40 50 60 70 80 90] | Slice(0 7 3) | Log ; => [10, 40, 70]
[10 20 30 40 50 60 70 80 90] | Slice(-9 -2 3) | Log ; => [10, 40, 70] : index -9 is same as 0, index -2 is same as 7

[info] [sample-wire] el
[info] [sample-wire] HloWrd
[info] [sample-wire] [20 30]
[info] [sample-wire] [10 40 70]
[info] [sample-wire] [10 40 70]