CFLib.org – Common Function Library Project

stripExtendedAscii(str)

Last updated August 30, 2011

author

Kevin Benore

Version: 2 | Requires: CF5 | Library: CFMLLib

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:

USAGE:

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

OR

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

Parameters:

Name Description Required
str String to modify. Yes

Full UDF Source:

/**
 * 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)
};

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson