Solved

how to get part of a string

Posted on 2006-06-29
6
176 Views
Last Modified: 2010-03-31
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
Comment
Question by:huzefaq
  • 4
6 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 17013443
String filename=website_url.getFile();
int ixSlash=0;
if ((ixSlash=filename.indexOf("/"))>-1) {
    filename= filename.substring(ixSlash+1);
}
0
 

Author Comment

by:huzefaq
ID: 17013734
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 17013766
>>I know there is a one line code to do this

Not that i know of
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 14

Accepted Solution

by:
hoomanv earned 300 total points
ID: 17013768
> filename.indexOf("/")
should'nt it be filename.lastIndexOf("/") ?   since you want   northcarolina
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17013784
>>should'nt it be filename.lastIndexOf("/") ?   since you want   northcarolina

Yes
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17013822
:-)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 62
Basic Java Case or If-Else statement... 3 50
Java Options in Zimbra Server 2 50
tomcat startup error 5 59
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question