
88
Chapter 4: Using Expressions and Pound Signs
Function syntax
The following table shows function syntax and usage guidelines:
All functions return values. In the following example, the
cfset
tag sets a variable to the value
returned by the
Now
function:
<cfset myDate = DateFormat(Now(), "mmmm d, yyyy")>
You can use the values returned by functions directly to create more complex expressions, as in the
following example:
Abs(Myvar)/Round(3.14159)
For more information on how to insert functions in expressions, see
“Using pound signs”
on page 89
.
Optional function arguments
Some functions take optional arguments after their required arguments. If omitted, all optional
arguments default to a predefined value. For example:
•
Replace("Eat and Eat", "Eat", "Drink")
returns "Drink and Eat"
•
Replace("Eat and Eat", "Eat", "Drink", "All")
returns "Drink and Drink"
The difference in the results is because the
Replace
function takes an optional fourth argument
that specifies the scope of replacement. The default value is “One,” which explains why only the
first occurrence of “Eat” was replaced with “Drink” in the first example. In the second example, a
fourth argument causes the function to replace all occurrences of “Eat” with “Drink”.
Expression evaluation and functions
It is important to remember that ColdFusion evaluates function attributes as expressions before it
executes the function. As a result, you can use any ColdFusion expression as a function attribute.
For example, consider the following lines:
<cfset firstVariable = "we all need">
<cfset myStringVar = UCase(firstVariable & " more sleep!")>
When ColdFusion server executes the second line, it does the following:
1
Determines that there is an expression with a string concatenation.
2
Evaluates the firstVariable variable as the string "we all need".
3
Concatenates "we all need" with the string " more sleep!" to get "we all need more sleep!".
4
Passes the string "we all need more sleep!" to the
UCase
function.
Usage
Example
No arguments
Function()
Basic format
Function(Data)
Nested functions
Function1(Function2(Data))
Multiple arguments
Function(Data1, Data2, Data3)
String arguments
Function('This is a demo')
Function("This is a demo")
Arguments that are expressions
Function1(X*Y, Function2("Text"))
Содержание COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...