How to remove ALL NON-ASCII characters from a variable?

I am using an external java applet that is very touchy about special characters.

Is there an easy way in Cold Fusion to simply strip or replace ALL NON-ASCII characters with a space or something similar?

Who is Participating?
siva_sivaConnect With a Mentor Commented:
Remove Non-ASCII character with space. Find the code attached.
	function CheckAsc(pw){
		i = 1;
		asciiremove = '';
		notAllowed = "44,46,59,64,124";
		while (i LTE len(pw)){
			nr = asc(mid(pw,i,1));			
			if (nr LT 33 OR nr GT 126 OR listFind(notAllowed,nr)){
				tset = Replace(mid(pw,i,1), mid(pw,i,1), " ");
				asciiremove = asciiremove & tset;
			else {
				asciiremove = asciiremove & mid(pw,i,1);
			i = i + 1;
		WriteOutput(asciiremove & "<br>");
	<cfset test = "">

Open in new window

gdemariaConnect With a Mentor Commented:
This will strip out non ascii characters.

<cfset variables.newString = rereplace(variables.string,"[^\x20-\x7E]","","all")>

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.