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
    Since your original replace example works as intended, it sounds like you are now struggling with the syntax for TeamSite. Unfortunately, I have never used it. So I cannot help you out there.
    Inspiring
    August 29, 2008
    I'm not sure how it would work, but do you think setting the value somewhere in a <cfscript> tag would make any difference, rather than using <cfset>?

    If there does not seem to be a easy CF solution, I may just need to see if I can contact the administrators for the cms instead.
    Inspiring
    August 29, 2008
    Thanks again. The first one gets an error from the CMS. The second one does not get any errors, but instead of displaying the value of myCMSFieldName, it just displays the actual word "myCMSFieldName."
    Inspiring
    August 29, 2008
    natg504 wrote:
    > <cfset strMainText = '{iw_value name="myCMSFieldName"/}' />
    > <cfset strMainText=Replace(strMainText, '&##', '&####', 'all') />

    I am not familiar with TeamSite, so I am veering into guesswork mode at this point ;-)

    Does "myCMSFieldName" represent FORM.input in your previous example? You might try using both quotes and # signs

    <cfset strMainText = '{iw_value name="#myCMSFieldName#"/}' />

    or possibly

    <cfset strMainText = '{iw_value name="'& myCMSFieldName &'"/}' />
    Inspiring
    August 29, 2008
    Well, we are using TeamSite & it seems like it requires quotes around the TeamSite variable when I assign the value to strMainText, so it reads it as a string, not just a variable. If I leave the quotes out, it errors on the < signs in the string instead. I'm not really sure how to get around that.


    <!--- Load maintext into variable --->
    <cfset strMainText = '{iw_value name="myCMSFieldName"/}' />
    <cfset strMainText=Replace(strMainText, '&##', '&####', 'all') />
    Inspiring
    August 29, 2008
    natg504
    > It's not working on my site for some reason... we're using a content
    > management system, which is where the input is coming from, so
    > maybe that has something to do with it.

    Yes, that is different. If you try it with a simple form the replace code does exactly what you are telling it to do. That is replace any # signs in form.input with ##.

    Can you post a small example that does not work?

    Inspiring
    August 29, 2008
    It's not working on my site for some reason... we're using a content management system, which is where the input is coming from, so maybe that has something to do with it.
    Inspiring
    August 29, 2008
    You only have to do that for your hard coded test that uses <cfset>. Your original example works just fine:

    <cfset strMainText = FORM.input />
    <cfset strMainText=Replace(strMainText, '##', '####', 'all') />
    Inspiring
    August 29, 2008
    But how do I do that if the string is coming from a form? I was just using that hard-coded string to test, but I can't control what someone enters into the form. If they enter a #, I can't even get to the Replace function before the error.
    Inspiring
    August 29, 2008
    natg504 wrote:
    > That didn't seem to work... here is what I am using to test:
    > <cfset strMainText = '<a href="#fn1">[1]</a>'>

    The problem is not the replace. You are missing a # sign in your cfset. You have to escape (ie double) pound signs so CF understands it is a literal "#" and not something to be evaluated.

    <cfset strMainText = '<a href="##fn1">[1]</a>'>
    Inspiring
    August 29, 2008
    ... Or use Ian's suggestion (ie ascii / chr )

    <cfset strMainText = '<a href="'& chr(35) &'fn1">[1]</a>'>