by
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
https://www.alihilal.com/snippets?id=swift-remove-whitespace-string
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/4576348/Remove-all-leading-and-trailing-white-sp?startLine=0"></iframe>
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