How to count the number of characters in a string without spaces and special characters in Swift

1 Answer

0 votes
import Foundation

let str = "(Swift), @#Programming: Language."

let filteredString = str.filter { $0.isLetter || $0.isNumber }

let characterCount = filteredString.count

print("Number of characters without spaces and special characters: \(characterCount)")



/*
run:

Number of characters without spaces and special characters: 24

*/

 



answered Jan 11, 2025 by avibootz
...