1
$\begingroup$

Following an example from my lectures I obtain this error and I cannot explain why it occurs.

The istructions are the following:

alphabet = CharacterRange["A","Z"];
string = "THIS IS THE TEXT TO ENCRYPT"
rc = RandomColor[26]
code = Table[alphabet[[n]]->rc[[n]],{n,Length[alphabet]}]
newstring = StringReplace[string, code]

but sometimes (but not always) I receive this error: "StringReplace::srep: Z->[] is not a valid string replacement rule" where [] stands for a certain color.

Could you help me to understand why it happens?

$\endgroup$
1
  • $\begingroup$ What OS? What version of Mathematica? Do you have any further information as to how you reproduce this more reliably? $\endgroup$
    – ktm
    Apr 3 '20 at 16:03
1
$\begingroup$

I just found the problem.

When I copied and pasted the code the symbol -> was treated as a rightarrow symbol [RightArrow] so the error occured.

Hope this could help someone else.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.