Trying to replace accents in Coldfusion

233 Views Asked by At

I am trying to remove accents from a string using REreplace but it is just not working.

Here is the string:

Alertas del Condado: Por favor, háganos saber si usted recibe este mensaje. Gracias.

Trying to remove the accent in "háganos" and replace it with "a".

Here is the code:

Rereplace(trans_sms, 'á', 'a', 'all')

Where trans_sms is the string.

I have been trying to search but cannot figure out why it is not replacing.

Thank you in advance for anyone's help!

1

There are 1 best solutions below

4
Adrian J. Moreno On

You don't use ColdFusion, you use Java.

Apache Commons StringUtils, function stripAccents

<cfscript>
    stringUtils = new java("org.apache.commons.lang3.StringUtils");
    accents = "á,é,í,ó,ú,ý,à,è,ì,ò,ù,â,ê,î,ô,û,ã,ñ,õ,ä,ë,ï,ö,ü,ÿ,À,È,Ì,Ò,Ù,Á,É,Í,Ó,Ú,Ý,Â,Ê,Î,Ô,Û,Ã,Ñ,Õ,Ä,Ë,Ï,Ö,Ü,x";
    simple = stringUtils.stripAccents(accents);
    writeOutput(accents & " <br> " & simple);
</cfscript>

Output:

á,é,í,ó,ú,ý,à,è,ì,ò,ù,â,ê,î,ô,û,ã,ñ,õ,ä,ë,ï,ö,ü,ÿ,À,È,Ì,Ò,Ù,Á,É,Í,Ó,Ú,Ý,Â,Ê,Î,Ô,Û,Ã,Ñ,Õ,Ä,Ë,Ï,Ö,Ü,x
a,e,i,o,u,y,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,x