Null Character

6 May 2007 01:22 (EST)
It looks like ColdFusion interpret the null character as an empty string instead of a valid character.

What would you see by running the following code? Length of "test" string will be 6, instead of 7.
<cfset test = "123" & Chr(0) & "abc" />
<cfoutput>#Len(test)#</cfoutput>

So basically you are loosing null character. This might not be a problem in most of the cases, but becomes quite important issue for a specific tasks as encryption and decryption where you have to control all ASCII characters.

In order to solve the problem and get correct results you should use URLDecode("%00") function instead of Chr(0), like in this example below:
<cfset test = "123" & URLDecode("%00") & "abc" />
<cfoutput>#Len(test)#</cfoutput>

The length is 7 now!
Tags coldfusion string char null zero nil ascii trick

AddThis Social Bookmark Button

How to compact MS Access database OpenID CFC: Consumer v.0.2

Comments

Drop a comment... don't be shy