CFLib.org – Common Function Library Project

stripExtendedAscii(str)

Last updated August 30, 2011

Version: 2 | Requires: ColdFusion 5 | Library: CFMLLib

 
Rated 1 time(s). Average Rating: 5.0

Description:
Removes all extended and non-printing ASCII characters for a string. For example you may have data that has TABs, LINE FEEDs (or CARRIAGE RETURNs), international letters, or non-printing characters that you simply want to remove, this function will delete them.

Return Values:
Returns a string.

Example:

view plain print about
USAGE:

<cfscript>stripExtendedAscii(VariableWithBadChars);</cfscript>

OR

<cfoutput>
#stripExtendedAscii(VariableWithBadChars)#
</cfoutput>

Parameters:

Name Description Required
str String to modify. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Removes all extended and non-printing ASCII characters from a string.
 * v2 by Adam Cameron
 * 
 * @param str      String to modify. (Required)
 * @return Returns a string. 
 * @author Kevin Benore (Kevin@Benore.net) 
 * @version 2, August 30, 2011 
 */

function stripExtendedAscii(str) {
  return reReplace(arguments.str, "[^\x20-\x7E]""""ALL"); // 0x20 = space, chr(32); \0x7E = ~ / tilde, chr(126)
};
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Robby Lansaw Robby Lansaw added
getComponentProp...
3 day(s) ago

Dave Anderson Dave Anderson added
iniToStruct
25 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
25 day(s) ago

Richard Richard added
dice
27 day(s) ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson