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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Akward replace 1

Status
Not open for further replies.
I'm not sure I understand what you are asking. You want to use the string but without the last part? Do you have code you're working with that may help to clarify?

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Why would you have two querystring variables with the same name? This is begging for problems (such as you're currently encountering). Can't you rename the variable? That would be the easiest (and best) solution.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
You can make a RegExp and replace.

Here is a code I copied/wrote up
Code:
<%@LANGUAGE="VBScript"%>
<%
InitialString = "?search=&day=&month=4&PAGE=8&latest=all&notfull=&Page=7"
eString = "?search=&day=&month=4&PAGE=8&latest=all&notfull=&Page=7"

Set RegExpObj = New RegExp

With RegExpObj
.Pattern = "&Page=\d{1,}"
.IgnoreCase = True
.Global = False
End With

InitialString = RegExpObj.Replace(InitialString, "")

Response.Write InitialString + "<br />"
Response.Write eString

Set RegExpObj = nothing
%>

Funny thing is though that for some reason it's printing funky characters at the "[!]&not[/!]full" part of the string, even before the replace.

Besides that, it replaces removes the first instance of &Page=number fine.


[monkey][snake] <.
 
One of these days, I'm really going to have to sit down and figure out RegEx... Nice job, monksnake!

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Thanks Chopstik

Code:
I'm really going to have to sit down and figure out RegEx

They really aren't that hard once you look at them. Before I knew much about them at all, it looked like Greek to me.

[monkey][snake] <.
 
It looks more Russian to me... [lol]

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
I am not sure if the solution proposed is satisfactory. I would offer a solution for multiple occurence of query on "page" whereby all instances will be deleted except the last occurrence. (More general case can be handled with some more involved twist.) Some technique used may be of some general interest. (I shortened some name to avoid potential wide-post.
[tt]
s="?se=&da=&mo=4&Page=8&la=all&no=&Page=7" 'op's line
'alternative testing line
's="?se=&da=&mo=4&Page=8&la=all&no=&Page=7&x=y&page=9&a=b"
's="?se=&da=&mo=4&Page=8&la=all"

set rx=new regexp
with rx
.ignorecase=true
.pattern="page=.*?(\&|$)"
end with

t=s
rx.global=true
set cm=rx.execute(t)
if cm.count>1 then
do while cm.count>1
rx.global=false
t=rx.replace(t,"")
rx.global=true
set cm=rx.execute(t)
loop
end if
response.write s & "<br />" & t
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top