Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 00:55
Be Careful Using "#" In ColdFusion DE() Expressions
<!---
Set phone and ext. In reality, these values would be
coming out of a data base or input form (over which we
do not have control).
--->
<cfset strPhone = "(123) 456-7890" />
<cfset strExt = "128" />
<!---
Create full phone number complete with base number and
line extension.
--->
<cfset strFullPhone = (
strPhone &
IIF(
Len( strExt ),
DE( " x#strExt#" ),
DE( "" )
)
) />
<!--- Output new number. --->
#strFullPhone#
<!---
Set phone and ext. In reality, these values would be
coming out of a data base or input form (over which we
do not have control).
--->
<cfset strPhone = "(123) 456-7890" />
<cfset strExt = "##128" />
<!---
Create full phone number complete with base number and
line extension.
--->
<cfset strFullPhone = (
strPhone &
IIF(
Len( strExt ),
DE(
Replace(
" x#strExt#",
"##",
"####",
"all"
)
),
DE( "" )
)
) />
<!--- Output new number. --->
#strFullPhone#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment