Evaluating String Expressions  
 
 

String expressions (which are often called dynamic expressions since their structure can easily change) can be evaluated using the Evaluate function. The Evaluate function takes a string expression, evaluates it, and returns the result. When ColdFusion is asked to evaluate the string expression "1+1", it produces the expected result of 2.

 
 
  Examples  
 

The following table illustrates the use of the Evaluate function:

Using the Evaluate Function 
CFML expression
Result
Evaluate("2") 2
Evaluate("2 * (11 MOD 3)") 4
Evaluate("Form.MyFormVariable") the value of Form.MyFormVariable
Evaluate("Min(X, Y)") the smaller of the values of X and Y
Evaluate(DE("Some text")) Some text
Evaluate(DE('A double quote "')) A double quote "

The guidelines for calling the Evaluate function are shown below:

Guidelines for Calling the Evaluate Function 
To get
Use
the result of (1 + A)
Evaluate("1 + A")
the value of variable A
Evaluate("A")
the number 2
Evaluate("2")
the string A
Evaluate(DE("A"))

Note the difference between the second and the fourth example. In the second example, we want to evaluate the expression A which should resolve to the value of the variable A (or an error if A does not exist). In the last example, we want to evaluate the expression "A" which should resolve to the text inside the string, or simply A. To inform ColdFusion of the difference (without worrying about escaping quotes), you call the DE function.



 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.