Skip to content

Instantly share code, notes, and snippets.

@cafielo
Created March 19, 2018 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cafielo/eb4fd5f9762d4cf0cc938f77b6f799c7 to your computer and use it in GitHub Desktop.
Save cafielo/eb4fd5f9762d4cf0cc938f77b6f799c7 to your computer and use it in GitHub Desktop.
extension String {
func trimTrailingWhitespaces() -> String {
return self.replacingOccurrences(of: "\\s+$", with: "", options: .regularExpression)
}
}
let string = "there is string with trailing whitespace "
let trimmed = string.trimTrailingWhitespaces()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment