Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion: convert accented regional characters to plain ASCII

I need to convert characters in French, Sweden and others language in their "normal" standard ASCII format.

I don't know how to explain, here's an example:

  • ç -> c
  • ò -> o

...

In bash Unix I would use iconv. How can I do in ColdFusion9 / Java?

like image 985
Fabio B. Avatar asked Mar 29 '12 13:03

Fabio B.


1 Answers

I found this simple UDF at CFLib.org:

deAccent

<cfscript>
/**
 * Replaces accented characters with their non accented closest equivalents.
 * 
 * @return Returns a string. 
 * @author Rachel Lehman ([email protected]) 
 * @version 1, November 15, 2010 
 */
function deAccent(str){
    var newstr = "";
    var list1 = "á,é,í,ó,ú,ý,à,è,ì,ò,ù,â,ê,î,ô,û,ã,ñ,õ,ä,ë,ï,ö,ü,ÿ,À,È,Ì,Ò,Ù,Á,É,Í,Ó,Ú,Ý,Â,Ê,Î,Ô,Û,Ã,Ñ,Õ,Ä,Ë,Ï,Ö,Ü,x";
    var list2 = "a,e,i,o,y,u,a,e,i,o,u,a,e,i,o,u,a,n,o,a,e,i,o,u,y,A,E,I,O,U,A,E,I,O,U,Y,A,E,I,O,U,A,N,O,A,E,I,O,U,Y";

    newstr = ReplaceList(str,list1,list2);
    return newstr;
}
</cfscript>
like image 71
ale Avatar answered Sep 30 '22 07:09

ale