CFLib.org – Common Function Library Project

stringToAscii(str)

Last updated June 17, 2010

author

Stephen Withington

Version: 1 | Requires: CF6 | Library: CFMLLib

Description:
Pass me a string and I'll convert it into HTML-friendly ASCII characters.

Return Values:
Returns a string.

Example:

<cfset str = "I’ve ¼ got © some ™ funky € characters ? to ? convert ¥ into ® ASCII ¶ eh?" />
<cfdump var="#stringToAscii(str)#" />

Parameters:

Name Description Required
str String to parse. Yes

Full UDF Source:

/**
 * I convert a string to ASCII characters.
 * 
 * @param str 	 String to parse. (Required)
 * @return Returns a string. 
 * @author Stephen Withington (steve@stephenwithington.com) 
 * @version 1, June 17, 2010 
 */
function stringToAscii(str) {
	var local = StructNew();
	local.oldStr = '';
	local.newStr = '';
	if ( StructKeyExists(arguments, 'str') and IsSimpleValue(arguments.str) ) {
		local.oldStr = arguments.str;
		for ( local.i=1; local.i lte Len(arguments.str); local.i++ ) {
			local.newStr = local.newStr & '&##' & Asc(Left(local.oldStr,1)) & ';';
			local.oldStr = RemoveChars(local.oldStr,1,1);
		};
	};
	return local.newStr;
};
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson