Advertisement
rAthus

[JavaScript] supprimer les accents d'une string

Nov 9th, 2016
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.prototype.sansAccent = function()
  2. {
  3.     var accent =
  4.     [
  5.         /[\300-\306]/g, /[\340-\346]/g, // A, a
  6.         /[\310-\313]/g, /[\350-\353]/g, // E, e
  7.         /[\314-\317]/g, /[\354-\357]/g, // I, i
  8.         /[\322-\330]/g, /[\362-\370]/g, // O, o
  9.         /[\331-\334]/g, /[\371-\374]/g, // U, u
  10.         /[\321]/g, /[\361]/g, // N, n
  11.         /[\307]/g, /[\347]/g, // C, c
  12.     ];
  13.     var noaccent = ['A','a','E','e','I','i','O','o','U','u','N','n','C','c'];
  14.     var str = this;
  15.     for(var i=0; i<accent.length; i++)
  16.         str = str.replace(accent[i], noaccent[i]);
  17.     return str;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement