CFLib.org – Common Function Library Project

convertSpecialChars(str)

Last updated January 3, 2011

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

 
Rated 6 time(s). Average Rating: 1.3

Description:
The function is useful for filtering out chars that may not display correctly when viewed in a text only format. Currently it converts open and close quotes to a normal qoute and converts slanted single quotes to normal single quotes

Return Values:
Returns a string.

Example:

view plain print about
<CFSET STR = "?special? quotes?">
<CFOUTPUT>
#STR# is converted to 
#ConvertSpecialChars(STR)#
</CFOUTPUT>
<I>You may need to "View Source" to see the changes.</I>

Parameters:

Name Description Required
str The string to modify. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Reformats special chars typically found when copying and pasting from Word.
 * v2 by James Moberg
 * 
 * @param str      The string to modify. (Required)
 * @return Returns a string. 
 * @author Glen Salisbury (gsalisbury@collegepublisher.com) 
 * @version 2, January 3, 2011 
 */

function ConvertSpecialChars(textin) {
       var bad = "#chr(145)#,#chr(146)#,#chr(147)#,#chr(148)#,#chr(151)#,#CHR(8217)#,#CHR(8216)#,#chr(188)#,#chr(189)#,#chr(190)#,#chr(174)#,#chr(173)#,#chr(169)#,#chr(160)#,#chr(153)#,#chr(150)#,#chr(149)#,#chr(133)#,#CHR(8220)#,#CHR(8221)#";
       var good = "',',"","",-,',',1/4,1/2,3/4,(R),-,(C), ,TM,--,*,...,"",""";
       return ReplaceList(textin, bad, good);
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

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

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

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while 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