Trim whitespace from a string


I want to remove all leading and trailing whitespace from a string.


// String literal
var s = "    Hello World!     "

// Trim all whitespace

s = s.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())


Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)