Here is my array and string:
var array = new Array('üÜ', 'ıI', 'iİ', 'ğĞ', 'şŞ', 'çÇ');
var string = 'İSTANBUL, ÜSKÜDAR, Çarşamba'
I'd to replace every (for ü) to [üÜ]. I mean [üÜ]SK[üÜ]DAR. Can anyone help me?
You can use replace() method
string.replace(/ü|Ü/g, '[üÜ]')
For all matches,
array.forEach(function(key){
string = string.replace(new RegExp('['+ key +']', 'g'), '['+ key +']');
});
function replaceAll(source, search, replace, ignoreCase) {
//SCAPE SPECIAL CHARACTERES.
var search1 = search.toString().replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
//IGNORE CASE SENSIVITY.
var ignore = (ignoreCase) ? "gi" : "g";
var result = source.replace(new RegExp(search1, ignore), replace);
return result;
}
var array = new Array('üÜ', 'ıI', 'iİ', 'ğĞ', 'şŞ', 'çÇ');
for (var i=0; i < array.length; i++){
array[i] = replaceAll(array[i],"ü", "üÜ",true);
}