Last active
July 31, 2021 10:56
-
-
Save deathlezz/59689b1f0f3555b6b2ddc1cf9c8e6bb4 to your computer and use it in GitHub Desktop.
Remove certain characters in Swift 5.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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