View comments | RSS feed

Special characters

The double quotation marks ("), single quotation mark ('), and pound sign (#) characters have special meaning to ColdFusion. To include any of them in a string, double the character; for example, use ## to represent a single # character.

The need to escape the single- and double-quotation marks is context-sensitive. Inside a double-quoted string, you do not need to escape single-quote (apostrophe) characters. Inside a single-quoted string, you do not escape double-quote characters.

The following example illustrates escaping special characters, including the use of mixed single and double quotes.

<cfset mystring = "We all said ""For He's a jolly good fellow.""">
<cfset mystring2 = 'Then we said "For She''s a jolly good fellow".'>
<cfoutput>
  #mystring#<br>
  #mystring2#<br>
  Here is a pound sign: ##
</cfoutput>

The output looks like this:

We all said "For He's a jolly good fellow."
Then we said "For She's a jolly good fellow."
Here is a pound sign: # 

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


Henweigh99 said on Jun 22, 2005 at 11:42 AM :
Sometimes when you have a web form, you don't have control over who is entering data - thus they may not know to escape things like quotes. It might be nice in this livedoc to explain how to use a ColdFusion function to correctly escape special characters once the form has been submitted.

David Levin <a href="http://www.angrysam.com">www.angrysam.com</a>

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/Elements14.htm