Mango Snippets » #1

Swift: How To Count Occurrences of a Character in a Swift String

To count occurrences of a character in a Swift String, you can use Sequence.filter and then Array.count:

"DoleeArts Tips".filter({ $0 == "e"}).count

Output:

2