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
Solved

how to get part of a string

Posted on 2006-06-29
6
181 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

790 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