Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

how to get part of a string

hi I get the file name of the url using this code

 URL website_url = new URL(request.getRequestURL().toString());
 request.setAttribute("WEBSITE_HOST", website_url.getHost());
request.setAttribute("WEBSITE_FILE", website_url.getFile());


the file can be something like this

/chapters/pub/northcarolina

now I need the last part northcarolina inthis example

Please if anyone can help how can I retreive that


Thanks
0
huzefaq
Asked:
huzefaq
  • 4
2 Solutions
 
CEHJCommented:
String filename=website_url.getFile();
int ixSlash=0;
if ((ixSlash=filename.indexOf("/"))>-1) {
    filename= filename.substring(ixSlash+1);
}
0
 
huzefaqAuthor Commented:
is there another method

I know there is a one line code to do this using a method from java api but donot remember it. Do you know anything about it.

Thanks for your help
0
 
CEHJCommented:
>>I know there is a one line code to do this

Not that i know of
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hoomanvCommented:
> filename.indexOf("/")
should'nt it be filename.lastIndexOf("/") ?   since you want   northcarolina
0
 
CEHJCommented:
>>should'nt it be filename.lastIndexOf("/") ?   since you want   northcarolina

Yes
0
 
CEHJCommented:
:-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now