Skip to Content

Replace Accented Characters Script

Does anyone have a JavaScript that they use in IDM that will take in a string and replace all accented characters with their non-accented equivalents? I've found a few online in non-IDM forums, like Stack Overflow or GitHub, that claim to work but when I plug them into IDM, they don't work.

If anyone has such a script that they use and know will work in IDM, I'd appreciate the knowledge transfer.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    May 16 at 05:42 PM

    Here is the script that I have tested and seems to work for me. This was actually developed by a co-worker of mine. Hopefully it can save someone some time someday.

    // Main function: Z_removeAccent
    
    
    
    
    function Z_removeAccent(strAccents) {
    	var strAccents = strAccents.split('');
    	var strAccentsOut = new Array();
    	var strAccentsLen = strAccents.length;
    	var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
    	var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
    	for (var y = 0; y < strAccentsLen; y++) {
    	if (accents.indexOf(strAccents[y]) != -1) {
    		strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1);
    	} else
    		strAccentsOut[y] = strAccents[y];
    	}
    	strAccentsOut = strAccentsOut.join('');
    	strAccentsOut = strAccentsOut.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
    	strAccentsOut = strAccentsOut.replace(/ /g, '');
    	return strAccentsOut;
    }
    

    Add comment
    10|10000 characters needed characters exceeded

    • LOL... Yes, you should recognize this one. Ya know, when I had this issue, I did not reach out to your team's IDM support and perhaps I should have done that. As a consultant, I still have some hesitation in asking the client for assistance because we're the consulting firm being hired for our expertise. We're supposed to have the answers. In my mind when I ask the client for help, it's like admitting to them that maybe we're not the experts we claim to be.

      That said, nobody is perfect and no one knows it all, especially when it comes to IDM. I shouldn't assume the client expects us to be superhuman. Perhaps in this situation I shouldn't have been so reserved and I should have asked your team for assistance. I will remember this as the project moves forward. :)

  • May 16 at 08:51 AM

    Hi Brandon,

    I tried the below script in IDM 8.0 SP4 version and it seems to be working. Hope it meets your requirement.

    Regards,

    Deva

    Add comment
    10|10000 characters needed characters exceeded

    • Right. I was looking for a complete script. The goal of this post was to save time and not have to develop my own full script since I assumed this wasn't the first time such a problem had cropped up in the world of IDM.

      In the end, my own co-worker had this script. He apparently ignored my email to the team asking if anyone had a script to do this so when I never got an answer from within my own company, I took to SCN. Intra-company communication would have gone a long way to save me time here but I digress.

      At least maybe someone else out there in the IDM development world can benefit from using this script! :)

  • May 16 at 10:29 AM

    Hi Brandon, attached is the script I put together for this purpose - perhaps overkill, as it handles a few very obscure characters.

    It also has an optional mode flag depending on whether you want it to return characters it could not convert (as its main purpose for me is for username generation, default behaviour strips any uncaught characters).

    Doubtless there will be some limitations/imperfections here, but hope it is useful for you. Also, it is tested in IDM 8.3, not 7.2, but I don't expect that would make a difference.

    Regards,
    Adam

    Add comment
    10|10000 characters needed characters exceeded