?
Solved

how to get part of a string

Posted on 2006-06-29
6
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 800 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Accepted Solution

by:
hoomanv earned 1200 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 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