Skip to content

Slice

Name - 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 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]&Int&[Int]
To 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]&Int&[Int]
Step 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
 9
10
11
12
13
;; 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] [shards/General/Slice/1.edn] el
[info] [shards/General/Slice/1.edn] HloWrd
[info] [shards/General/Slice/1.edn] [20 30]
[info] [shards/General/Slice/1.edn] [10 40 70]
[info] [shards/General/Slice/1.edn] [10 40 70]