Remove diacritics


/ Published in: ActionScript 3
Save to your folder(s)

remove diacritics with the possibility convert to lowercase


Copy this code and paste it in your HTML
  1. function removeDiacritics(text:String, lowerCase:Boolean = false):String {
  2. var mapDi:String="áäàâčçďéěëèêíïîĺľňóôöŕšťúůüùûýřžÁÄÀÂČÇĎÉĚËÈÊÍÏÎĹĽŇÓÔŒÖŔŠŤÚŮÜÙÛÝŘŽ";
  3. var mapNo:String="aaaaccdeeeeeiiillnooorstuuuuuyrzAAAACCDEEEEEIIILLNOOSORSTUUUUUYRZ";
  4. var strOut:String="";
  5. lowerCase?text=text.toLocaleLowerCase():null;
  6. for (var i:uint = 0; i < text.length; i++) {
  7. if (mapDi.indexOf(text.charAt(i))!=-1) {
  8. strOut+=mapNo.charAt(mapDi.indexOf(text.charAt(i)));
  9. } else {
  10. strOut+=text.charAt(i);
  11. }
  12. }
  13. return strOut;
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.