Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace all accented vowels using ColdFusion

Is there any way to dynamically replace accented characters such as the following?

requesón => requeson

What I mean is that every accented (or whatever) character would be replaced with the normal one.

Is this possible using ColdFusion?

like image 798
Jordelca Avatar asked Dec 20 '25 09:12

Jordelca


1 Answers

You can fix accented characters through java text normalization and a regex. There is a function on cflib that does this already:

From: http://cflib.org/udf/deAccent

function deAccent(str){
    //based on the approach found here: http://stackoverflow.com/a/1215117/894061
    var Normalizer = createObject("java","java.text.Normalizer");
    var NormalizerForm = createObject("java","java.text.Normalizer$Form");
    var normalizedString = Normalizer.normalize(str, createObject("java","java.text.Normalizer$Form").NFD);
    var pattern = createObject("java","java.util.regex.Pattern").compile("\p{InCombiningDiacriticalMarks}+");
    return pattern.matcher(normalizedString).replaceAll("");
}
like image 184
2 revs, 2 users 86%Peter Boughton Avatar answered Dec 23 '25 00:12

2 revs, 2 users 86%Peter Boughton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!