35 8

Remove all leading and trailing white spaces of string in Swift

handy Swift string extension that helps to remove all leading and trailing white spaces in a string
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import Foundation extension String { func strip() -> String{ return self.trimmingCharacters(in: CharacterSet.whitespaces) } } // White spaced string var string = " Hello, World " string.strip() //Result -> "Hello, World"
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus