[Mono-list] System.Text.RegularExpression question
Rob Hudson
rob@euglug.net
Thu, 15 Apr 2004 15:52:43 -0700
Hello,
Short and sweet: Does C# have a way to transpose letters?
I'm new to C# and as a learning tool, I'm trying to convert an old
cryptogram generator I wrote in perl[1]. I converted the same program
in Python when I was learning some Python[2].
The Perl code had one line in it that I can't find in C#. The line is
similar to the following...
$text =~ tr/ABC/XYZ/;
...except it is the full alphabet tranposed to the full alphabet
randomly shuffled. It should replace each instance of 'A' with 'X',
each instance of 'B' with 'Y', etc.
The documentation at http://www.go-mono.com:8080/ says "To be added"
when looking up System.Text.RegularExpressions.Regex.
I realize I can run a loop and perform a Regex.Replace on each letter,
but thought there might be a better way.
Or maybe C# has a String.Translate method similar to Python?
Thanks for any help.
Cheers!
Rob
[1] http://www.cogit8.org/rob/code/txt/cryptogram.txt
[2] http://www.cogit8.org/rob/blog/Languages/Python/200307180749.txt