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

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

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

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson