Working with CFML expressions
25
For more information and examples on using number signs in expressions, see
ColdFusion MX
Developer’s Guide
.
Specifying quotation marks around values
When you assign literal values to variables, you must surround the literal value with single- or
double-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. In
the following example, when you concatenate literal text and variables using the & operator, you
don’t surround the variable references with quotation marks:
<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 use two consecutive
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 you use 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 them as the start or end of a tag
rather than as an operator.
Содержание COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...COLDFUSION MX7 Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 14: ...14 Chapter 1 Introducing ColdFusion MX...
Страница 38: ...38 Chapter 3 Database Fundamentals...
Страница 40: ......
Страница 58: ...58 Chapter 5 Lesson 2 Configuring Your Development Environment...
Страница 70: ...70 Chapter 6 Lesson 3 Retrieving Data...
Страница 84: ...84 Chapter 7 Lesson 4 Building Dynamic Queries...
Страница 96: ...96 Chapter 8 Lesson 5 Creating a Trip Detail Page...
Страница 102: ...102 Chapter 9 Lesson 6 Creating a Main Application Page...