2017-07-10 18 views
0

私はrot13.comに最終的にsimularのテキストコンバータを再作成しようとしています。しかし、私は特定の文字を別の文字に変換する方法を知らない。私が入力したいと思えば;文字の置き換え

それから私は、出力が

rcszqarいくつかのより

になりたいでしょう。

NST ABC> SNV

foo>のGPP

バー>私は、関係なく、私はその行に変更何の数字どれをreturn String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + i) ? c : c - 26);

を使用していない。しかしよそれらが正しく置き換えられます。

答えて

0

機能はここに文書化されています http://stackoverflow.com/a/617685/987044

 function rot(s, i) {   return s.replace(/[a-zA-Z]/g, function (c) { 
       return String.fromCharCode((c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + i) ? c : c - 26);   });   }  function update() {    document.getElementById('output').value = rot(document.getElementById('input').value, 
+document.getElementById('rot').value);   } 

関数を呼び出すときに変更する必要がある唯一の数は変数iです。例えば、

rot ("example", 13);//->"rcszqar" 
関連する問題