Reputation: 93193
I have the following String :
def s="txtimgtxtvdd"
i want to extract a list from the String above as following
def l=["txt","img","txt","vdd"]
Each 3 consecutive letters is an item of list
Upvotes: 1
Views: 463
Reputation: 171084
You can use collate
(and toList
to split the string into a list of chars)
def part = 'txtimgtxtvdd'.toList().collate( 3 )*.join()
assert part == ['txt', 'img', 'txt', 'vdd']
Upvotes: 3