5

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?

ale
  • 6,369
  • 7
  • 55
  • 65
Fabio B.
  • 9,138
  • 25
  • 105
  • 177

2 Answers2

9

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 (raelehman@gmail.com) 
 * @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>
ale
  • 6,369
  • 7
  • 55
  • 65
  • Obviously you can add whatever characters you need. There's nothing native in ColdFusion to do this sort of conversion. You might be able to use something in the underlying Java (see [Sergii's comment](http://stackoverflow.com/questions/9926507/coldfusion-convert-accented-regional-characters-to-plain-ascii/9926760#comment12671936_9926507)). – ale Mar 29 '12 at 14:56
-2

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

encodedString = charsetEncode(stringToBeConverted, "utf-8");
Tom
  • 57
  • 2
  • 6
  • I tried a simple example of the code: But it gives me error: Parameter 1 of the CharsetEncode function, which is now x, must be a valid binary object. Is there anything missing? – FlexyBoz Sep 26 '13 at 10:12