Groovy web console

subscribe to the feed Subscribe
to this
site

94793

Published 4 months ago by mao with tags tokenise
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def foo(String x) {
    x
        ?.tokenize('-')
        ?.drop(1)
        ?.join('-')  
    ?:  'default'
}

println(":::${foo('a')}:::")
println(":::${foo('')}:::")
println(":::${foo('-a')}:::")
println(":::${foo('a-')}:::")
println(":::${foo('a- ')}:::")
println(":::${foo('a-b-c-')}:::")
println(":::${foo()}:::")