Groovy web console

subscribe to the feed Subscribe
to this
site
return only chars after the first occurence of FindString (via #groovywebconsole)
tweet this snippet Tweet
this
script

return only chars after the first occurence of FindString

Published 1 month ago by The5neak with tags string manipulation
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
//return only chars after the first occurence of FindString
FindString="-"
SourceString="firstpart-second-part"

//println SourceString.find(/[-]{1}/)
println SourceString
println "Where is the first - :" + (SourceString.indexOf(FindString)+1)
println "What is the length of the string :" + SourceString.length()
println "Return only chars after the first occurence of - :" + SourceString[SourceString.indexOf(FindString)+1..SourceString.length()-1]