Posted By

tuffstudio on 10/27/12


Tagged


Versions (?)

String converter


 / Published in: JavaScript
 

example of use:

var translationTable = { a:1, bb:2, b:3, c:4 }; var MyTranslater = CreateTranslator( translationTable ); MyTranslater('aabbbc'); // returns: 11234

  1. function CreateTranslator(translationTable) function(s) s.replace(new RegExp([k for (k in translationTable)].join('|'), 'g'), function(str) translationTable[str]);

Report this snippet  

You need to login to post a comment.