Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2008, 06:37 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default Removing unknowm number of breaks from string

Good day

I get a feeling the code I have to remove an unknown number of breaks from the end of a string can be done better. I am using this CuteSoft WYSIWYG editor. Im not a fan of it, all these damn <br>'s keep get thrown on the end every time the form is submitted. Such a pain in the ***

Anyhow the teaxt area may be fairly long in some cases. My code to detect and get rid of the <br>'s is:

  dim runAgain,newStr
  thStr = "The difficulty of launching and recovering seaboats<br><br><BR>"
  runAgain = true

  do until runAgain = false
     if (right(thStr,3) = "br>" or right(thStr,3) = "BR>") then
        thStr = left(thStr,(len(thStr)-4))
        runAgain = true
     else
        runAgain = false
     end if
  loop

Any suggestions on making this code better would be appriciated.

TYIA

Wind is your friend
Matt
www.elitemarquees.com.au
__________________
Wind is your friend
Matt
 
Old October 15th, 2008, 08:00 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Code:
<%
...
thStr = "The difficulty of launching and recovering seaboats<br><br><BR>"

Set reZap = New RegExp
reZap.Pattern = "(\<br[^\>]*\>)+$"
reZap.IgnoreCase = True

thStr = reZap.Replace( thStr, "" )
...
%>
That will handle all variants of a <br> tag, including
<br style="something or other">
<br class="whatever">
<br >
<br/>
and more.

It says:
( )+ -- one or more times
$ -- at the end of the text
\<br -- look for a starting <br
[^\>]* -- followed by any number of non-> characters
\> -- and finally a > character
And then the replace zaps all of those, replacing them with a blank string.

If you'd like to provide for spaces and/or newlines mixed in amongst the <br>s, either before or after or between, just change to:
Code:
reZap.Pattern = "(\s*\<br[^\>]*\>)+\s*$"
Completely untested, off the top of my head. Still warranted against all bugs* for 30 picosends or 30 bits, whichever comes first.

*bugs must have 6 or 8 legs to be covered.
 
Old October 15th, 2008, 08:16 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

what can I say except for wow, a very powerful couple of lines. As always your code is top shelf!!

I will test further as I not only need to run this for new inserts and updates but on all the currently stored data.

Have a fine day, your time is very much apprciated.

Wind is your friend
Matt
www.elitemarquees.com.au
 
Old October 15th, 2008, 08:18 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Oh and BTW than you for the explanation and breakdown. Im sure:

"(\<br[^\>]*\>)+$"

would be veru confusing to alot of people :o)

Wind is your friend
Matt
www.elitemarquees.com.au





Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform String, Removing Characters. v01 XSLT 3 November 21st, 2008 01:58 PM
Removing leading zeros from a string value vikkiefd XSLT 2 June 12th, 2008 03:30 AM
Removing Double Quotes from a string Durkee VB.NET 2002/2003 Basics 12 October 4th, 2007 12:10 PM
Removing Double Qoutes from string hexOffender VB.NET 2002/2003 Basics 2 June 26th, 2006 02:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.