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
huzefaqAsked:
Who is Participating?
 
hoomanvConnect With a Mentor Commented:
> filename.indexOf("/")
should'nt it be filename.lastIndexOf("/") ?   since you want   northcarolina
0
 
CEHJConnect With a Mentor Commented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
CEHJCommented:
>>I know there is a one line code to do this

Not that i know of
0
 
CEHJCommented:
>>should'nt it be filename.lastIndexOf("/") ?   since you want   northcarolina

Yes
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.