Solved

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

Posted on 2007-11-26
2
3,854 Views
Last Modified: 2013-12-16
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?

Thanks,
Dasher
0
Comment
Question by:dasher3000
2 Comments
 
LVL 5

Accepted Solution

by:
siva_siva earned 250 total points
ID: 20356732
Remove Non-ASCII character with space. Find the code attached.
<cfscript>

	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>");

		return;

	}

</cfscript>
 

<cfoutput>

	<cfset test = "cir.cl.e">

	#CheckAsc("#test#")#

</cfoutput>

Open in new window

0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 250 total points
ID: 20367515
This will strip out non ascii characters.



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

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now