Rot-13: Difference between revisions

Content added Content deleted
(Undo revision 104951 by 122.3.171.14 (talk) Vandalism)
(Improved D version)
Line 392: Line 392:


=={{header|D}}==
=={{header|D}}==
<lang d>import std.stdio, std.string;
{{works with|D|2}}
<lang d>string rot13(string s) {
alias std.string.letters Alpha ;
enum Rot13 = Alpha[13..26]~Alpha[0..13]~Alpha[39..52]~Alpha[26..39] ;
return std.string.tr(s, Alpha, Rot13) ;
}</lang>


string rot13(string text) {
alias letters L;
enum r13 = L[13..26] ~ L[0..13] ~ L[39..52] ~ L[26..39];
return text.tr(L, r13);
}

void main() {
writeln("Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt!".rot13());
}</lang>
Output:
<pre>The Quick Brown Fox Jumps Over The Lazy Dog!</pre>
{{works with|D|1}}
{{works with|D|1}}
<lang d>import std.stdio, std.string;
<lang d>import std.stdio, std.string;