Groovy web console

subscribe to the feed Subscribe
to this
site
How to get the first word of every line of a String in Groovy (via #groovywebconsole)
tweet this snippet Tweet
this
script

How to get the first word of every line of a String in Groovy

Published 3 months ago by Vyacheslav Enis
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def projectString = """Lorem ipsum dolor
sit amet odio
magnis vitae iaculis"""

projectString = projectString
    .readLines()
    .collect { it[0.. it.indexOf(' ')] }
    .join("\n")

println projectString