Copy link to clipboard
Copied
Team,
In my code I'm trying to dynamically replace the # with ##.
Code is ,
Not able to find the reason why this happens,
Hi , thank you, we wrapped the display value with Evaluate() function , this resolved the issue. Thanks
Copy link to clipboard
Copied
There's an old joke that goes like this: someone goes to a doctor and complains "it hurts when I do this". The doctor replies "don't do this". That's what your question reminds me of. Don't try to escape hash marks in the middle of an expression the way you're doing. You might be able to get it to work, but there's almost certainly an easier way to do what you want.
Dave Watts, Eidolon LLC
Copy link to clipboard
Copied
Separately, I'd argue we can't solve the problem without seeing the values in question. Show us which "key" value works and which does not.
Also, you can often help yourself in this situation by creating a simple test page that does ONLY what's needed to present the problem. That way any of us could run it to confirm we see the same result...but often in creating such a simple test page, one will more easily recognize the problem and solution on their own.
Copy link to clipboard
Copied
The displayed ## and # suggest that the end-results were, respectively, the strings '####' and '##'.
Is that not what you expected? If not, what are the original field names and what did you expect the end-results to be?
Did you, for example, expect just one # to be displayed in every case? Or the double ## to be displayed in every case?
Also, could you include code that shows how we go from localStruct.AdditionalFieldsToUpdateStruct[key] to local.fields[FiName].Display ?
Copy link to clipboard
Copied
@Vishnu22410012h6s8 , Have you solved the problem already? If not, then provide the information asked for and you will get a solution. This problem need not interrupt your work. It is simple to solve.
Copy link to clipboard
Copied
Hi I expect single # to be displayed in UI. I added the below fix because, if user enters # in the text area field and saves, error page will occur. This could be because coldfusion doesn't allow single #. The below piece of code is in a repository, say ABC.
Copy link to clipboard
Copied
I expect single # to be displayed in UI.
By @Vishnu22410012h6s8
Thanks for that explanation. If you expect just a single # in each case, then the following code won't work
replace(localStruct.AdditionalFieldsToUpdateStruct[key],'##','####','all')
That is because this code replaces "####" with "##". To illustrate with a different example, the result of
<cfoutput>#replace("Time flows.","flows","flies")#</cfoutput>
is: Time flies.
Suggestion:
<cfset localStruct.AdditionalFieldsToUpdateStruct={myKey1='myValue1',myKey2='##myValue2',myKey3='####myValue3',myKey4='######myValue4'}>
<cfloop collection="#localStruct.AdditionalFieldsToUpdateStruct#" item="key">
<cfset localStruct.AdditionalFieldsToUpdateStruct[key]= REreplace(localStruct.AdditionalFieldsToUpdateStruct[key],'(#chr(35)#){2,}','#chr(35)#','all')>
<cfoutput>#"Key=" & key & "; " & "localStruct.AdditionalFieldsToUpdateStruct[key]=" & localStruct.AdditionalFieldsToUpdateStruct[key]#</cfoutput> <br>
</cfloop>​
The result is:
Copy link to clipboard
Copied
Hi Vishnu, did that solve the # problem?
Copy link to clipboard
Copied
Hi , thank you, we wrapped the display value with Evaluate() function , this resolved the issue. Thanks
Copy link to clipboard
Copied
Thanks for the update.