Hey all,
can anybody please help me out here?
Why does the following line not replace every character that appears more than once in the string?
str = "AAbCC";
StringReplace[str, c_ -> "X" /; StringCount[str, c] > 1]
Does anyone have a more elegant solution?
Still learning Mathematica, sorry…
Thank you and all the best
Timo
Got it.
Once you do it right, it works 
StringReplace[str, c_ /; (StringCount[str, c] > 1) -> "X"]
mhelmle
(Michael Helmle)
3
Alternatively you can do it this way:
StringReplace[str, c_ ~~ c_ -> "XX"]
For anyone interested. Here’s my complete code. From time to time I try to solve exercises from codewars in different languages.
This one is based on this one Duplicate Encoder | Codewars
On[Assert];
singleEncode = "(";
doubleEncode = ")";
distinctChars = "ABCDE";
distinctCharsMixed = "AbCdE";
doubledChars = "AABBCCDDEE";
doubledCharsMixed = "AabBCcDdEe";
encodeString[s_String] :=
StringReplace[
s, {(c_ /; (StringCount[s, c, IgnoreCase -> True] > 1) ->
doubleEncode), (c_ -> singleEncode)}];
Assert[encodeString[distinctChars] == "((((("]
Assert[encodeString[distinctCharsMixed] == "((((("]
Assert[encodeString[doubledChars] == "))))))))))"]
Assert[encodeString[doubledCharsMixed] == "))))))))))"]