Mathematica, 46 bytes
Count[Characters@#,c_/;RemoveDiacritics@c!=c]&
ToExplanations:
Chatacters
extract every characters in the string. Note that there is a difference between two Zoë
even if they look the same:
Characters["Zoë"]
(* {"Z", "o", "ë"} *)
Characters["Zoë"]
(* {"Z", "o", "e", "̈ ̈"} *)
Here, the pattern c_/;RemoveDiacritics@c!=c
will be honestmatched with those characters that change with diacritics removed. For the first case, I do not really understandonly ë
will match since ë
becomes e
. While for the descriptionsecond case, only :P ̈
will match since it becomes nothing. Whatever case the string is, but the function just workscounting will be correct.
Test cases:Test cases:
f=%; (* assign the function to f. *)
f["Zoë reads the encyclopædia in a café"]
(* 3 *)
f["Zoe reads the encyclopaedia in a cafe"]
(* 0 *)
f["Zoë"]
(* 1 *)
f["Zoë"]
(* 1 *)
f["déjà vu"]
(* 2 *)