?
Solved

VBScript code to delete any data between two characters

Posted on 2009-05-14
4
Medium Priority
?
624 Views
Last Modified: 2012-05-07
I'm completely stumped on how to do this.

I have a file full of html code. I need to search through it and remove some code. The problem I have is that there is variable between [ and ], and I am not sure how to go about this.

I'm use to using replace and variables etc at a basic level, but this is well beyond me!

example code:
Stuff I need to keep<br /><font color="#ff0000">[variable data]</font><br /><font color="#000000">More stuff here I need to keep


I need a script/function to search and delete, leaving me with:
Stuff I need to keep<br /><br /><font color="#000000">More stuff here I need to keep

The square brackets don't appear anywhere else in the file, so they can be used as an anchor point for the deletion.
0
Comment
Question by:Burns2007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:BarryTice
ID: 24394601
First, read your text file into a single string variable, say, strText.
Then, try something like this:
Do While InStr(strText, "[") > 0
  intLeft = InStr(strText, "[")
  strLeft = Left(strText, intLeft - 23)
  intRight = InStr(strText, "]")
  strRight = Right(strText, Len(strText) - strRight - 7)
  strText = strLeft & strRight
Loop
 
This could be optimized somewhat for speed and memory usage, but this is nice and clear.

Open in new window

0
 
LVL 27

Expert Comment

by:bluntTony
ID: 24395575
Hi,

Try this as well.

Pass the text into strText and it'll remove all the of [text] portions.
While InStr(strText,"[") > 0
	intOpen = InStr(strText,"["):intClose = InStr(strText,"]")
	strText = Replace(strText,Mid(strText,intOpen,(intClose-intOpen)+1),"")
Wend

Open in new window

0
 
LVL 27

Expert Comment

by:bluntTony
ID: 24395598
Barry, i couldn't personally get yours to work. What are the 23 and 7 for?

Not saying it's wrong but I like to get my head round other methods.
0
 
LVL 1

Accepted Solution

by:
maytan80 earned 1455 total points
ID: 24397349
Use the split method. It will create an array on the variable

so x<y>z

I would do a split on "<" character giving me a 2 record array x and y>z
then do a split on > giving me x in the first array and y and z in the second array

Now mix and match

character array m = split(str, character/delimiter)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question