in reply to char substitution without regexes
You said you wanted different thinking ....
ikegami shows how to generate the map for one character. Use that to generate a set of maps for all possible two character strings, use that to generate a set of maps for all three character strings.
When you reach the length of the input string, do a hash lookup, and voila!
Obviously slower than doing one string with tr///, but maybe worth it if you have a large number of strings to process.
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
|
|---|