Groovy web console

subscribe to the feed Subscribe
to this
site

What You See Is What You Almost Get

Published 3 months ago by MS with tags No break spaces
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
//Ideal output
String idealSentance = "Many    spaces   between   each   word"

//Current WYSIWYG output
String outputSentance = "Many    spaces   between   each   word"


StringBuilder sb = new StringBuilder()
//Loop through each new word
outputSentance.split(" ").each{
    if(it){
        sb.append(it).append(" ")
    } else {
        sb.append(" ")
    }
}

String resultantSentance = sb.toString().trim()
println resultantSentance 

(resultantSentance ==idealSentance)