Skip to main content
Inspiring
May 5, 2008
Question

How to get around # sign

  • May 5, 2008
  • 17 replies
  • 1948 views
I have to use '#DCDEE0' for a color background, but sometime CF interprets it as a variable and blow up because there is not ending # sign.

What is the trick to get around this? Some screens work and some dont.
    This topic has been closed for replies.

    17 replies

    Inspiring
    August 29, 2008
    That didn't seem to work... here is what I am using to test:

    <cfset strMainText = '<a href="#fn1">[1]</a>'>
    <cfset strMainText = replace(strMainText,chr(36),chr(36) & chr(36),'ALL')>
    <cfoutput>#strMainText#</cfoutput>



    Here is the error I get:

    Invalid CFML construct found on line 10 at column 36.
    ColdFusion was looking at the following text:
    \"

    The CFML compiler was processing:

    An expression that began on line 10, column 32.
    Your expression might be missing an ending "#" (it might look like #expr ).
    an expression beginning with "\'", on line 10, column 22.This message is usually caused by a problem in the expressions structure.
    a cfset tag beginning on line 10, column 2.


    The error occurred in testReplace.cfm: line 10

    8 : <body>
    9 :
    10 : <cfset strMainText = '<a href="#fn1">[1]</a>'>
    11 :
    12 : <cfset strMainText = replace(strMainText,chr(36),chr(36) & chr(36),'ALL')>



    Inspiring
    August 29, 2008
    natg504 wrote:
    > How can this be done dynamically? For example,
    >
    > <cfset strMainText = FORM.input />
    > <cfset strMainText=Replace(strMainText, '##', '####', 'all') />
    >
    > This seems like it should work, but I get an error.
    >

    Go askii on your problem!

    replace(strMainText,chr(36),chr(36) & chr(36),'ALL')
    Inspiring
    August 29, 2008
    How can this be done dynamically? For example,

    <cfset strMainText = FORM.input />
    <cfset strMainText=Replace(strMainText, '##', '####', 'all') />

    This seems like it should work, but I get an error.
    June 4, 2008
    When using colors, just leave off the pound sign in the first place. It's optional.
    Inspiring
    June 4, 2008
    quote:

    Originally posted by: Kling
    When using colors, just leave off the pound sign in the first place. It's optional.

    You realize you get different colours when you do that, right?
    Inspiring
    May 7, 2008
    no, not only inside a <cfoutput> tag.
    you also need to escape # when used inside attributes in cf tags, i.e.
    <cfinput style="color:##333;"> or in <cflocation> if you are using a
    named anchor in the url attribute.


    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    May 7, 2008
    Yes, there are rules about when you need to escape # signs. But what I was getting at, in my round-about way, was to RTM ;-) The online documentation even came up as the first result in google ..
    May 7, 2008
    It should be noted that ## is only need when inside a <cfoutput> tag.
    Inspiring
    May 5, 2008
    A quick google for: ColdFusion # signs

    Turned up:
    To display a number sign on a page, you must designate the number sign as a literal character. You do this by using two number signs (##)
    http://livedocs.adobe.com/coldfusion/7/htmldocs/00000087.htm