Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

<CFSET mystring2 =Replace(mystring1,"</div></div>","","ALL")>

Participant ,
Jan 13, 2012 Jan 13, 2012

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 ""?

4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 22, 2012 Jan 22, 2012

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")>

Translate
LEGEND ,
Jan 14, 2012 Jan 14, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 14, 2012 Jan 14, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 14, 2012 Jan 14, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 15, 2012 Jan 15, 2012

So how can I tell whats between the </div></div> tags?

Should I try <CFSET mystring2 =Replace(mystring1,"</div>CR</div>","","ALL")>?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 15, 2012 Jan 15, 2012

Use the asc() function to see what's between the tags.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 16, 2012 Jan 16, 2012

How do I use this asc() function?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 16, 2012 Jan 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2012 Jan 15, 2012

</div></div>

Why insist on doing it on the double? You could just do

<CFSET mystring2 =replaceNoCase(mystring1,"</div>","","ALL")>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 16, 2012 Jan 16, 2012

</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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 16, 2012 Jan 16, 2012

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 16, 2012 Jan 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 16, 2012 Jan 16, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 16, 2012 Jan 16, 2012

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2012 Jan 22, 2012
LATEST

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")>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 21, 2012 Jan 21, 2012

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources