title: How to manipulate Strings in Scala while using the Play framework?
body: <p>I am using the play framework 2.2.1 and I have a question concerning the manipulation of Strings within view templates. Unfortunately I am not very familiar with the Scala programming language nor its APIs. The strings are contained in a List which is passed from the controller to the view and then I use a loop to process each string before they are added to the html. I would like to know how to do the following: trim, toLowerCase and remove spaces. As an example, if I have "My string ", I would like to produce "mystring". More specifically I would actually like to produce "myString", however I'm sure I can figure that out if someone points me in the right direction. Thanks.</p>
  
  <p>UPDATE:</p>
  
  <p>Fiaz provided a great solution, building on his answer and just for interest sake I came up with the following solution using recursion. This example is of course making many assumptions about the input provided.</p>
  
  <pre><code>@formatName(name: String) = @{  
    def inner(list: List[String], first: Boolean): String = {
      if (!list.tail.isEmpty &amp;&amp; first) list.head + inner(list.tail, false)
      else if (!list.tail.isEmpty &amp;&amp; !first) list.head.capitalize + inner(list.tail, false)
      else if (list.tail.isEmpty &amp;&amp; !first) list.head.capitalize
      else list.head                  
    } 
    if (!name.trim.isEmpty) inner(name.split(' ').map(_.toLowerCase).toList, true)        
    else ""
  }
  </code></pre>