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

Removing Whitespace from within a string

New Here ,
Aug 30, 2008 Aug 30, 2008
I have a string that I'm trying to remove any HTML existing within it.

Here is the REReplace:
<cfset VARIABLES.stripped_content = REReplaceNoCase(getevents.calevent_content,"<[^>]*>","","ALL") >

After this I'm trying to output the first 97 characters of the screen as preview text...however that reg replace leaves a ton of whitespace that appears to be messing up my Left() function.

How do I get rid of all that whitespace generated from the rereplace??

Thanks!!
Paul
4.2K
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
Valorous Hero ,
Aug 30, 2008 Aug 30, 2008
paulferree wrote:
> How do I get rid of all that whitespace generated from the rereplace??

I suspect it is not the rereplace. Are you using a cffunction by any chance?
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 ,
Aug 30, 2008 Aug 30, 2008
No, it's literally:

<cfset VARIABLES.stripped_content = REReplaceNoCase(getevents.calevent_content,"<[^>]*>","","ALL") > <cfoutput>#Left(VARIABLES.stripped_content,97)#</cfoutput>

I do need to say that the whitespace isn't viewable on the browser, but in the code view I see it...and when I run the Left() function it seems to be including the whitespace in the count...which is the problem.

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
Valorous Hero ,
Aug 30, 2008 Aug 30, 2008
> I do need to say that the whitespace isn't viewable on the browser, but in the code view I see it.

Yes, I understand. I tried your expression and it does not add any extra whitespace for me. If you run these lines, what results do you get?

<cfsavecontent variable="getevents.calevent_content">
This is plain text <br class="clear-both"> with some html <h4>thrown in</h4> from
time to literal time ..<p class="time stamp-date">08/30/2008 12:18:17 PM</p>
</cfsavecontent>

<!--- trim the value _before_ the regex --->
<cfset VARIABLES.stripped_content = REReplaceNoCase(Trim(getevents.calevent_content),"<[^>]*>","","ALL") >
<cfoutput>
length = #len(VARIABLES.stripped_content)#<br>
<pre>|#VARIABLES.stripped_content#|</pre><br>
left(97) = #left(VARIABLES.stripped_content, 97)#
</cfoutput>
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 ,
Sep 01, 2008 Sep 01, 2008
Your example went fine..but when I replaced your HTML with a snippet of the actual HTML being evaluated I get the same problem...here it is.

The Code:

=======
<cfsavecontent variable="getevents.calevent_content">
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
<font color="#d3d3d3">
<font face="Arial">
<span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">9am-1:30pm<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /??><o:p></o:p></span>
<font size="2">
</font>

</font>
</font>
</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
<font color="#d3d3d3">
<font face="Arial">
<span style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">Contact:<span style="mso-spacerun: yes"> </span>Some Name @ 555-555-5555<o:p></o:p></span>

<font size="2">
</font>
</font>
</font>
</p>
</cfsavecontent>

<!--- trim the value _before_ the regex --->
<cfset VARIABLES.stripped_content = REReplaceNoCase(Trim(getevents.calevent_content),"<[^>]*>","","ALL") >
<cfoutput>
length = #len(VARIABLES.stripped_content)#<br>
<pre>|#VARIABLES.stripped_content#|</pre><br>
left(97) = #left(VARIABLES.stripped_content, 97)#
</cfoutput>
=======

The Output (notice the whitespace):
=======

length = 180

|


9am-1:30pm









Contact: Some Name @ 555-555-5555





|


left(97) = 9am-1:30pm
=======

Could have something to do with that UGLY HTML that I have to work with. However, in ASP this was outputted on the legacy site using:

<%# this.GetChars(Eval("content") as String, 75) %>

Seemed to work ok but I can't really test it.

Thanks!
Paul
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
Valorous Hero ,
Sep 01, 2008 Sep 01, 2008
paulferree wrote:
> The Output (notice the whitespace):
> =======
> length = 180

Strange. I ran the exact code with CF 8 and the length = 81. The original string (with the html) was length = 602.
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 ,
Sep 01, 2008 Sep 01, 2008
hmm.. maybe thats the problem then. I'm running CF 6.1 or something.
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
Valorous Hero ,
Sep 02, 2008 Sep 02, 2008
paulferree wrote:
> hmm.. maybe thats the problem then. I'm running CF 6.1 or something.

Perhaps. I am not aware of any behavior differences with 6.1. The only whitespace issues I can think of are related to cffunctions and occasional strange behavior when output="true".

In the worth a shot category, you might try a plain replace(...). Replace two spaces consecutive spaces with a single space.
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 ,
Sep 02, 2008 Sep 02, 2008
LATEST
Well..I thought I tried that previously but apparently I just copy and pasted the REReplace...which obviously wouldn't work. I didn't realize it until your comment. So I tried it and it does better, but there is still some undesired spaces. I'll just deal with it, it's just trying to compensate for some legacy DB entries.

Thanks!
Paul
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