Split a string in lengths of 3 Hello becomes [ Hel , ell , llo ]

n1ql

#1

how do i split a string into an array in the below way .
Lets say i have a string . “Hemanth” . I want a json string to be generated as follows .

[ { “splitStr”: [ “hem”, “ema”, “man”, “ant”, “nth” ] } ]

I know i can use some thing like -
select array substr(“hemanth”,i,3) for i in [0,1,2,3,4] end as splitStr

But i want [0,1,2,3,4] to be generated in dynamic way based on length of input string .

select array substr(,i,3) for i in [0,1,2,3,4] end as splitStr


#2

You were almost there…
select array substr(“hemanth”,i,3) for i in array_range(0,length(“hemanth”)-2,1) end as splitStr