I needed to trim a string and also replace more than one spaces with a single space. The solution was simple with String.replace in JavaScript....