Groovy web console

subscribe to the feed Subscribe
to this
site
string spliter using tokenize (via #groovywebconsole)
tweet this snippet Tweet
this
script

string spliter using tokenize

Published 2 weeks ago by Abhinandan with tags Vaani
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
String originalContent  = "thi sis the thing which I wanted to told ou. but as you know mu nature i couldnt confess what i did."

List tokenizedContents = originalContent.tokenize()

        int breakingThreshold = 10
        int index = 0

List segments = []
def tempSegment = null

int contentSize = tokenizedContents.size()


print("\n\ncontentSize**\n"+contentSize)

while(index <= (contentSize - 1) ){
print("\n \n *** Entry index: ***\n"+index)

if((index + breakingThreshold) >= contentSize){
tempSegment = tokenizedContents[index..(contentSize - 1)]

print("\n\n**IF tempSegment **\n"+tempSegment)
} else{

tempSegment = tokenizedContents[index..(index + (breakingThreshold - 1))]

print("\n\n**ELSE tempSegment **\n"+tempSegment)

}

index = index + breakingThreshold

print("\n \n *** Exit index: ***\n"+index)

}