Skip to main content
August 11, 2008
Question

Function returning extra whitespace

  • August 11, 2008
  • 4 replies
  • 827 views
I created a function to strip all non-numeric characters from a string and format the phone number in a specific manner, but the string that is returned has a <space> at the beginning of the number every time. Using TRIM() does not need to remove the extra whitespace. Any ideas?
This topic has been closed for replies.

4 replies

August 11, 2008
I guess setting output="no" worked even though I swear I tried that already... thanks!
Inspiring
August 11, 2008
Basically if you do not put output="false" then it will leave the white space for the the cftags it has removed to leave the result. It is a crap behaviour and is there because functions can output text without having to return it. It is a crap behaviour IMO however some people want to use it that way.

I wish cffunction had output="false" as default instead of the other way round, but that would be beginning of a long wish-list!
August 11, 2008
I had used TRIM() in these 2 scenarios:

<cfreturn trim(tmpPhone)>

and when calling the function:

#TRIM(FormatPhone(varaible))#

The value of "variable" may be "123-456-7890"
Inspiring
August 11, 2008
add output="false" to your cffunction declaration
Inspiring
August 11, 2008
Sorry I didn't notice that straight away but I have been putting that in by default for so long that I forgot about that behaviour!
Inspiring
August 11, 2008
I don't see you using trim anywhere? Also, what is the number you are passing in your test?