Skip to content

Instantly share code, notes, and snippets.

@deathlezz
Last active July 31, 2021 10:56
Show Gist options
  • Save deathlezz/59689b1f0f3555b6b2ddc1cf9c8e6bb4 to your computer and use it in GitHub Desktop.
Save deathlezz/59689b1f0f3555b6b2ddc1cf9c8e6bb4 to your computer and use it in GitHub Desktop.
Remove certain characters in Swift 5.
//
// Remove certain characters
//
let input = "1 234 567".filter {!$0.isWhitespace}
let input2 = "aAbBcCdD".filter {!$0.isLowercase}
let input3 = "!@A#$BC%DE^FG&HI".filter {!$0.isLetter}
let input4 = "1234abcd Abcd!#$%".filter {$0.isLetter}
print(input) // 1234567
print(input2) // ABCD
print(input3) // !@#$%^&
print(input4) // abcdAbcd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment