views:

130

answers:

1

Running Coldfusion 8, I am trying to clean text input before saving to a database that will take things like the MS equivalent of ' " - and accented letters, and converting them.

I have tried replace, REReplace, and various UDFs found on the internet. None seem to work. In fact, I tried this:

<cfscript>
    function cleanString(string) {
       var newString = string;
       newString = replace("'", "'", ALL);
       return newString; 
    }
</cfscript>

The single quote to be replaced above is a MS Word style single quote. Coldfusion threw an error, the error scope said invalid syntax and the single quote in the error scope was a square. If I change it to the chr() form, and replace with ', I get a blank. If I do chr() to the entity, I get a blank.

I am more than certain I have jumped this hurdle before, and not sure why nothing is working now. Is there a new setting in CF8 vs CF7 regarding character encoding that I am missing?

+5  A: 

There is a great script for demoronizing (yes, that's a technical term) text copied from MS word and the like. It can be found at CFLib:
http://cflib.org/index.cfm?event=page.udfbyid&amp;udfid=725

I've used it several times, and been happy with it out-of-the-box (though I have added some additions for specific applications).

Ben Doom
+1 (Funny we need a demoronizing script to get rid of "smart quotes")
Leigh
@Leigh -- no one said programmers aren't funny. Well, probably someone did, but they were wrong.
Ben Doom
@Ben - Dead wrong ;)
Leigh