Fabio B.
Fabio B.

Reputation: 9410

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:

...

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

Upvotes: 5

Views: 5221

Answers (2)

Tom
Tom

Reputation: 57

you can also use the charsetEncode function built in to CF.

encodedString = charsetEncode(stringToBeConverted, "utf-8");

Upvotes: -2

ale
ale

Reputation: 6430

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>

Upvotes: 9

Related Questions