From: scott on
I'm trying to get the querystring value from a url that is stored in a
database. In the examples below, I'm trying to get the "prodID" value from
each string or url.

Asyou can see, the "prodID" querystring name can appear anywhere within the
url and I never knowhow many digits the "prodID" value is.

Any ideas on getting the value after any occurance of "prodID="?

Examples:

http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322
http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322
http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322
http://www.mysite.com/products.asp?prodID=7


From: "Dave "Crash" Dummy" on
scott wrote:
> I'm trying to get the querystring value from a url that is stored in a
> database. In the examples below, I'm trying to get the "prodID" value from
> each string or url.
>
> Asyou can see, the "prodID" querystring name can appear anywhere within the
> url and I never knowhow many digits the "prodID" value is.
>
> Any ideas on getting the value after any occurance of "prodID="?
>
> Examples:
>
> http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322
> http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322
> http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322
> http://www.mysite.com/products.asp?prodID=7

msgbox
prodID("http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322")
msgbox
prodID("http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322")
msgbox
prodID("http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322")
msgbox prodID("http://www.mysite.com/products.asp?prodID=7")

function prodID(URI)
query=split(URI,"?")(1)
items=split(query,"&")
for n=0 to ubound(items)
if split(items(n),"=")(0)="prodID" then
prodID=split(items(n),"=")(1)
exit for
end if
next
end function
--
Crash

Committed to the search for intraterrestrial intelligence.
From: scott on
Works great. I was going at it with string functions and pulling hair out.

"Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message
news:ZNTPn.36984$rU6.31501(a)newsfe10.iad...
> scott wrote:
>> I'm trying to get the querystring value from a url that is stored in a
>> database. In the examples below, I'm trying to get the "prodID" value
>> from each string or url.
>>
>> Asyou can see, the "prodID" querystring name can appear anywhere within
>> the url and I never knowhow many digits the "prodID" value is.
>>
>> Any ideas on getting the value after any occurance of "prodID="?
>>
>> Examples:
>>
>> http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322
>> http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322
>> http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322
>> http://www.mysite.com/products.asp?prodID=7
>
> msgbox
> prodID("http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322")
> msgbox
> prodID("http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322")
> msgbox
> prodID("http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322")
> msgbox prodID("http://www.mysite.com/products.asp?prodID=7")
>
> function prodID(URI)
> query=split(URI,"?")(1)
> items=split(query,"&")
> for n=0 to ubound(items)
> if split(items(n),"=")(0)="prodID" then
> prodID=split(items(n),"=")(1)
> exit for
> end if
> next
> end function
> --
> Crash
>
> Committed to the search for intraterrestrial intelligence.


From: James Whitlow on
> "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message
> news:ZNTPn.36984$rU6.31501(a)newsfe10.iad...
>> scott wrote:
>>> I'm trying to get the querystring value from a url that is stored in a
>>> database. In the examples below, I'm trying to get the "prodID" value
>>> from each string or url.
>>>
>>> Asyou can see, the "prodID" querystring name can appear anywhere within
>>> the url and I never knowhow many digits the "prodID" value is.
>>>
>>> Any ideas on getting the value after any occurance of "prodID="?
>>>
>>> Examples:
>>>
>>> http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322
>>> http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322
>>> http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322
>>> http://www.mysite.com/products.asp?prodID=7
>>
>> msgbox
>> prodID("http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322")
>> msgbox
>> prodID("http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322")
>> msgbox
>> prodID("http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322")
>> msgbox prodID("http://www.mysite.com/products.asp?prodID=7")
>>
>> function prodID(URI)
>> query=split(URI,"?")(1)
>> items=split(query,"&")
>> for n=0 to ubound(items)
>> if split(items(n),"=")(0)="prodID" then
>> prodID=split(items(n),"=")(1)
>> exit for
>> end if
>> next
>> end function

"scott" <sbailey(a)mileslumber.com> wrote in message
news:eAFSpDCCLHA.4400(a)TK2MSFTNGP05.phx.gbl...
> Works great. I was going at it with string functions and pulling hair out.

As an alternative, you can also use the 'RegExp' object.

Dim oRegEx, aURL(3), i

Set oRegEx = CreateObject("VBScript.RegExp")
oRegEx.Pattern = "prodID=(\d*)"

aURL(0) = "http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322"
aURL(1) =
"http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322"
aURL(2) =
"http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322"
aURL(3) = "http://www.mysite.com/products.asp?prodID=7"

For i = 0 to 3
If oRegEx.Test(aURL(i)) Then
MsgBox oRegEx.Execute(aURL(i))(0).Submatches(0), , "prodID"
End If
Next


From: Evertjan. on
James Whitlow wrote on 10 jun 2010 in
microsoft.public.scripting.vbscript:

> As an alternative, you can also use the 'RegExp' object.
>
> Dim oRegEx, aURL(3), i
>
> Set oRegEx = CreateObject("VBScript.RegExp")
> oRegEx.Pattern = "prodID=(\d*)"

oRegEx.Pattern = "(\?|\&)prodID=(\d*)"

and

Submatches(1)

to prevent 'otherprodID=' from matching.


>
> aURL(0) =
> "http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322"
> aURL(1) =
> "http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322"
> aURL(2) =
> "http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322"
> aURL(3) = "http://www.mysite.com/products.asp?prodID=7"
>
> For i = 0 to 3
> If oRegEx.Test(aURL(i)) Then
> MsgBox oRegEx.Execute(aURL(i))(0).Submatches(0), , "prodID"
> End If
> Next
>
>

Sometimees one wonders,
why the VBS regex is so much less readable than the Javascript equivalent:

var temp, aURL= [
"http://www.mysite.com/products.asp?prodID=12&catID=5&classID=322",
"http://www.mysite.com/products.asp?classID=7&prodID=9&classID=322",
"http://www.mysite.com/products.asp?prodID=180&catID=15&classID=322",
"http://www.mysite.com/products.asp?prodID=7"
];

for (var i=0;i<aURL.length;i++)
if (temp = aURL[i].match(/(\?|\&)prodID=(\d+)/))
alert( 'prodID\n\n' + temp[2] );


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)