Trim whitespace from a string

 Problem

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



 Recipe


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

// Trim all whitespace

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

print(s)
				


 Playground