0
Removing Whitespace from within a string
Community Beginner
,
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/td-p/133652
Aug 30, 2008
Aug 30, 2008
Copy link to clipboard
Copied
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/m-p/133653#M12445
Aug 30, 2008
Aug 30, 2008
Copy link to clipboard
Copied
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?
> 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?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
paulferree
AUTHOR
Community Beginner
,
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/m-p/133654#M12446
Aug 30, 2008
Aug 30, 2008
Copy link to clipboard
Copied
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.
<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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/m-p/133655#M12447
Aug 30, 2008
Aug 30, 2008
Copy link to clipboard
Copied
> 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>
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>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
paulferree
AUTHOR
Community Beginner
,
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/m-p/133656#M12448
Sep 01, 2008
Sep 01, 2008
Copy link to clipboard
Copied
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/m-p/133657#M12449
Sep 01, 2008
Sep 01, 2008
Copy link to clipboard
Copied
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.
> 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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
paulferree
AUTHOR
Community Beginner
,
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/m-p/133658#M12450
Sep 01, 2008
Sep 01, 2008
Copy link to clipboard
Copied
hmm.. maybe thats the problem then. I'm running CF 6.1 or
something.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/m-p/133659#M12451
Sep 02, 2008
Sep 02, 2008
Copy link to clipboard
Copied
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.
> 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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
paulferree
AUTHOR
Community Beginner
,
LATEST
/t5/coldfusion-discussions/removing-whitespace-from-within-a-string/m-p/133660#M12452
Sep 02, 2008
Sep 02, 2008
Copy link to clipboard
Copied
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
Thanks!
Paul
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

