In this tutorial, we are going to learn about how to trim the whitespaces from a string in Swift.
To remove the leading and trailing whitespaces from a string, we can use
trimmingCharacters(in:) method by passing a
offered by the swift.
Here is an example:
let str = " Oxygen " let trimmedStr = str.trimmingCharacters(in: .whitespaces) print(trimmedStr)