String manipulation of a URL - strip preceding characters?

B

Bob Barrows

jason said:
How would I strip out everything from before the last "/" in the
following string generated from request.servervaraibles method:

http://www.essermanyachtsales.com/riverbend/

...so that I was just left with:

"Riverbend"

Many thanks

Jason
This particular string is easy:

dim str,ar
str="http://www.essermanyachtsales.com/riverbend/"
ar = split(str,"/")
response.write ar(ubound(ar))

However, who is to say that your string might not contain
"http://www.essermanyachtsales.com/riverbend/default.asp"?
Now, you would have to do this:
ar = split(str,"/")
response.write ar(ubound(ar)-1)

So, use If:

ar = split(str,"/")
if right(str,1) = "/" then
response.write ar(ubound(ar))
else
response.write ar(ubound(ar)-1)
end if

Of course, you have to check to make sure str contains any characters at all
....

HTH,
Bob Barrows
 
A

Aaron Bertrand - MVP

This is where using ar(3) would always get the base subfolder...
True - depends on what he wants. He DID say " ... everything from before the
last "/" ..."

Right, which is why I didn't say, "you should use ar(3) instead." :)
 
J

jason

I guess I should be specific that I cannot always know in advance how many
subfolders there will be after the url...BUT...I always need to know what is
the LAST subfolder and its content...

Does this make sense....

Does ar(3) still work is it fixed folder?
 
J

jason

Thanks - stupid question: What if I always wanted to get the LAST subfolder
in the url no matter how many subfolders appear in the url....would this
still work?

- Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top