Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-11-26
2
Medium Priority
?
3,868 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
siva_siva earned 1000 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 1000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

610 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