Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete characters between "|"

Status
Not open for further replies.
May 31, 2007
31
AE
Hi all,

I am trying to delete characters between a start and stop character. I have currently set this character to "|"

how do I delete the characters in between?

any help will be appreciated. thanks in advance
 
And what have YOU tried so far ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

This is what i have so far ! I have change the "|" to "<" and ">" below


str = "<Field1> Test"

mypos = instr(str,"<")
for x=mypos+1 to len(str)
if mid(str,x,1)=">" Then
str = Mid(str, x, len(str))
str = Replace(str,">","")
MsgBox str
end If
Next

this works if the str is as above

however if thr str is

str = "<Field1> Test <approved>"

then the <approved> is not removed.

 
What about this ?
myStr = "<Field1> Test <approved>"
i = InStr(myStr,"<"): j = InStr(myStr,">")
While i > 0 And j > i
myStr = Left(myStr,i-1) & Mid(myStr,j+1)
i = InStr(myStr,"<"): j=InStr(myStr,">")
Wend
MsgBox myStr

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[tt]set rx=new regexp
with rx
.global=true
.pattern="<[^>]*?>"
end with

str="<Field1> Test <approved>"
t=rx.replace(str,"")
wscript.echo str & vbcrlf & t[/tt]
 
I like tsuji's method witht the regexp.

I'm going to clean up the pattern just a bit though. Since you want to remove the characters between '<' and '>', if there are no characters between <>, there is nothing to remove, so we really don't need to match that in the regexp.

This is what I have for a pattern:
Code:
.pattern="<[^>]+>"

[monkey][snake] <.
 
Thanks everyone,

Your help has enabled me to achieve what I wanted.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top