Remove all leading and trailing white spaces of string in Swift
handy Swift string extension that helps to remove all leading and trailing white spces in a string
extension String {
func strip() -> String {
return self.trimmingCharacters(in: .whitespaces)
}
}
// White spaced string
var string = " Hello, World "
string.strip()
// Result -> "Hello, World"