Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > String manipulation of a URL - strip preceding characters?

Reply
Thread Tools

String manipulation of a URL - strip preceding characters?

 
 
jason
Guest
Posts: n/a
 
      07-23-2003
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



 
Reply With Quote
 
 
 
 
Aaron Bertrand - MVP
Guest
Posts: n/a
 
      07-23-2003
url = "http://www.essermanyachtsales.com/riverbend/"
url = split(url, "/"): response.write url(3)



"jason" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      07-23-2003
jason wrote:
> 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


 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      07-23-2003
Aaron Bertrand - MVP wrote:
>> 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)

>
> Except what if it is
> "http://www.essermanyachtsales.com/riverbend/subfolder/default.asp"?
>
> 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 "/" ..."

Bob


 
Reply With Quote
 
Aaron Bertrand - MVP
Guest
Posts: n/a
 
      07-23-2003
> > 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."


 
Reply With Quote
 
jason
Guest
Posts: n/a
 
      07-23-2003
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?
"Aaron Bertrand - MVP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > > 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."
>
>



 
Reply With Quote
 
jason
Guest
Posts: n/a
 
      07-23-2003
Thanks


"Bob Barrows" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Aaron Bertrand - MVP wrote:
> >> 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)

> >
> > Except what if it is
> > "http://www.essermanyachtsales.com/riverbend/subfolder/default.asp"?
> >
> > 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 "/" ..."
>
> Bob
>
>



 
Reply With Quote
 
jason
Guest
Posts: n/a
 
      07-23-2003
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
"Aaron Bertrand - MVP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> > > 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."
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strip all but second second line from bottom and then strip that!!!! yelipolok Perl Misc 4 01-27-2010 08:14 AM
Preceding with partial string rnakawat@gmail.com XML 1 06-06-2008 01:05 PM
URL string manipulation adam bob XML 1 09-25-2007 03:07 PM
Strip Query String from url Scott ASP General 8 09-04-2006 04:10 PM
strip and its evil brother strip! Aquila Ruby 35 03-31-2005 04:10 AM



Advertisments