VBS - Remove excess tags at EOF

February 9, 2010 at 09:28:22
Specs: Windows XP
Hi all,

I've successfully written a VB script that
translates a text file into HTML. However, for
some reason, probably due to the formatting of
the original text file, I get 4 to 5 <'br'> tags at
the end of my file.

How would I go about creating a script that
removes these excess <'br'> tags? There does exist tags within the file that I'd like to
keep, so it's not as simple as a find and
replace all.

During the conversion from text->HTML, I store the entire text file into a String variable. It might be easier to edit this String variable to remove the tags before I save it into a new file, as opposed to attacking this after the fact.

Thanks,
R


See More: VBS - Remove excess tags at EOF

Report •

#1
February 9, 2010 at 10:37:09
During the conversion from text->HTML, I store the entire text file into a String variable. It might be easier to edit this String variable to remove the tags before I save it into a new file, as opposed to attacking this after the fact.
I'd take it one step further. It'd be better to strip out whatever is causing the errant break tags before beginning your conversion.

Report •

#2
February 9, 2010 at 11:05:36
The breaks are just in there as a result of a replaceAll.
I'm doing this:

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, chr(13) & chr(13), "<'br'><'br'>")

So at the end of my file there are unwanted chr(13)
characters, which become unwanted break characters. I can't
figure out anything unique about these characters that would
allow me to flag them and distinguish from other similar
characters throughout the file.

edit: I guess there is one distinct characteristic: No non-break characters will ever come after the last break one(s).


Report •

#3
February 9, 2010 at 14:09:45
one way might be:

...
strText = objFile.ReadAll
objFile.Close
Lt=len(strNewText)
do while right(strNewText,1)=chr(13)
Lt=Lt-1
strNewText=left(strNewText,Lt)
loop
strNewText=Replace(strNewText,chr(13),"
")
...


Report •
Related Solutions


Ask Question