User Guide
Working with CFML expressions 25
Specifying quotation marks around values
When assigning literal values to variables, you must surround the literal value with double
quotation marks or single quotation marks. ColdFusion interprets the content between the
quotation marks as a literal value and assigns that value to the variable; for example:
<cfset my_first_name = "Kaleigh">
<cfset my_last_name = "Smith">
<cfset my_age = 5>
ColdFusion instantiates the variable my_first_name to the string literal Kaleigh. Further, Smith
is assigned to the variable
my_last_name and 5 is assigned to age.
When referencing a variable by its name, you do not surround the name with quotation marks;
for example:
<cfset the_string = "My name is " & variables.my_first_name &
" and my age is " & variables.my_age>
My name is
is literal text and, you therefore, surround it with quotation marks. The variable
references
variables.my_first_name and variables.my_age are not surrounded by
quotation marks. ColdFusion uses the values of the referenced variables (
Kaleigh and 5,
respectively) when assigning the value to the variable
the_string.
To display quotation marks on a page as literal characters, you must double the quotation marks;
for example:
<cfset mystring = "We all shouted ""Happy Birthday"" when he entered the
room.">
<cfoutput>
#mystring#
</cfoutput>
The result is the following output:
We all shouted "Happy Birthday" when he entered the room.
Specifying operators in expressions
In ColdFusion, you use operators to test conditions; for example, you use the
IS operator to test
for equality. When using operators in expressions, you must only use supported logical operators
that ColdFusion can interpret properly. For example, if you use the greater than operator (>)or
the less than operator (<), ColdFusion interprets these operators as the start or end of a tag.
The following table lists the nonsupported logical operators and their equivalent ColdFusion
operators:
Nonsupported
logical operator
Equivalent ColdFusion
decision operator Description
= IS, EQUAL, EQ Tests for equality.
< LT, LESS THAN Tests for less than.
<= LTE, LE,
LESS THAN OR EQUAL TO
Tests for less than or equal to.
>GT
GREATER THAN
Tests for greater than.