Copy link to clipboard
Copied
I am trting to replace the words </div></div> with "" from a string that I have.
I am using the code <CFSET mystring2 =Replace(mystring1,"</div></div>","","ALL")> and the tag does not replace </div></div> from my string.
Ive been a CF proogrammer for 15 years and used this tag hundreds of times but I cant figure out why the Replace tag wont Replace </div></div>.
I dont even need to replace them I could just remove them.
Any help on removing the </div></div> from my string or replacing it with ""?
weezerboy wrote:
I cant remove just one of the </div> tags.
There are instances in my code that I need to keep one </div> tag.
I need to get rid of </div></div>
Ah, I understand. Then use a regular expression, asking it to match any occurrences with 0 or more spaces between the two tags. Something like this:
<cfset mystring2 = REReplaceNoCase(mystring1,"</div>\s*</div>","","all")>
Copy link to clipboard
Copied
Are you sure the string contains "</div>" rather than - say - "</DIV>"? Or is there perhaps whitespace or other non-printable characters between the two </div? tags?
--
Adam
Copy link to clipboard
Copied
Adam,
Here is what the code looks like in DW.
<textarea cols="250" name="editor1" rows="250<div id="shadowboxnew"><div class="container"><cfinclude template="../dev/cms_content/#url.pagename#"></div></div></textarea>
I am able to parse out /Replace other pieces of text but I can t get rid of the </div></div>
Here is how it shows up in the source code after I try to parse out /Replace
</div>
</div>
Ideally I really dont want to replace </div></div> .
I want to remove the </div></div>
Let me know
Copy link to clipboard
Copied
If it's on two lines, then there's some manner of line break between them (ie: a CR or and LF or both). When you're wondering what's in a string, don't just "look at it on the screen", examine each character in it.
--
Adam
Copy link to clipboard
Copied
So how can I tell whats between the </div></div> tags?
Should I try <CFSET mystring2 =Replace(mystring1,"</div>CR</div>","","ALL")>?
Copy link to clipboard
Copied
Use the asc() function to see what's between the tags.
Copy link to clipboard
Copied
How do I use this asc() function?
Copy link to clipboard
Copied
How do I use this asc() function?
Is it not in the docs? (yes, OK, rhetorical question: of course it is):
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e26.html
So what I normally do in situations wherein I think a string contains something but it seems it actually contains something else (like this example), I "walk" the string, char by char, and look at the ASCII code of each char.
--
Adam
Copy link to clipboard
Copied
</div></div>
Why insist on doing it on the double? You could just do
<CFSET mystring2 =replaceNoCase(mystring1,"</div>","","ALL")>
Copy link to clipboard
Copied
</div></div>
Why insist on doing it on the double? You could just do
<CFSET mystring2 =replaceNoCase(mystring1,"</div>","","ALL")>
My presumption was that a single </div> is OK, it's situations that there are two that is the problem. Although that's obviously just as assumption. Yours is a legit question (not that you were asking for validation from me!), as the OP might be over-engineering the solution.
I'd perhaps decide whether the string that needs replacing is "a run of two closing div tags", or whether "a closing div tag followed by zero or more whitespace or other non-printing characters followed by another closing div" is adequate. I strongly suspect the latter is more likely the requirement, in which case it's an easy regex.
--
Adam
Copy link to clipboard
Copied
Adam...Is there a way to find out what these "invisible" characters are between my </div></div> tags>
I cant see them in my code?
Are there some characters you could suggest that I try?
Copy link to clipboard
Copied
Adam...Is there a way to find out what these "invisible" characters are between my </div></div> tags>
I cant see them in my code?
Are there some characters you could suggest that I try?
Our responses overlapped. I answered this in my previous answer (to the one about "how does one use asc()").
--
Adam
Copy link to clipboard
Copied
Well I tried as you suggested...I think
I did this with only </div></div> in my form textbox
and I put this code on the page that is trying to determine the characters <cfoutput>#Asc("Form.textbox")#</cfoutput>
I get 70
With </div></div> ...<cfoutput>#Asc("Form.textbox")#</cfoutput> = 70
What does that mean.?
How do I walk the string ?
I am submitting the string in a textarea field with the </div></div> tags to an action page wher I am trying to parse out the </div></div> tags
Copy link to clipboard
Copied
I cant remove just one of the </div> tags.
There are instances in my code that I need to keep one </div> tag.
I need to get rid of </div></div>
Copy link to clipboard
Copied
weezerboy wrote:
I cant remove just one of the </div> tags.
There are instances in my code that I need to keep one </div> tag.
I need to get rid of </div></div>
Ah, I understand. Then use a regular expression, asking it to match any occurrences with 0 or more spaces between the two tags. Something like this:
<cfset mystring2 = REReplaceNoCase(mystring1,"</div>\s*</div>","","all")>
Copy link to clipboard
Copied
to "walk thru the characters (in a table to see clearer):
<cfoutput>
<table border="1">
<cfloop from="1" to="#len(form.textbox)#" index="thisone">
<tr><td> #mid(form.textbox,thisone,"1")#</td>
<td> #asc(mid(form.textbox,thisone,"1")#</td>
</tr>
</cfloop>
</table>
</cfoutput>
That might help, but I can't see why you are including another page in your textbox?
Also, I notice there is no "> at the end of that textarea opening tag:
<textarea cols="250" name="editor1" rows="250"><div id="shadowboxnew"><div class="container"><cfinclude template="../dev/cms_content/#url.pagename#"></div></div></textarea>
Find more inspiration, events, and resources on the new Adobe Community
Explore Now