Eliminar espacios de string / Trimming the whitespace from a string

/*If you need to trim the extra spaces off the beginning and end of your string, use stringByTrimmingCharactersInSet.*/ var myString = " Let's trim the whitespace " var newString = myString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) //Returns "Let's trim the whitespace" /*You can also easily remove whitespace and new line characters at the same time using this character set:*/ var newString = myString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.