Created
September 18, 2014 08:19
-
-
Save ypetya/2ed78cb0cc7f538c1699 to your computer and use it in GitHub Desktop.
Replace diacritics in javascript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var replaceDiacritics = function (string) { | |
var diacritics = [ | |
/[\300-\306]/g, /[\340-\346]/g, // A, a | |
/[\310-\313]/g, /[\350-\353]/g, // E, e | |
/[\314-\317]/g, /[\354-\357]/g, // I, i | |
/[\322-\330]/g, /[\362-\370]/g, // O, o | |
/[\331-\334]/g, /[\371-\374]/g, // U, u | |
/[\321]/g, /[\361]/g, // N, n | |
/[\307]/g, /[\347]/g, // C, c | |
]; | |
var chars = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u', 'N', 'n', 'C', 'c']; | |
for (var i = 0; i < diacritics.length; i++) { | |
string = string.replace(diacritics[i], chars[i]); | |
} | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment