This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I have a String that I need to break into parts to use one of the values.
Example: // This value actually comes from request.getReqestURI(); String uri = "/Servlet/Case.html";
What I need is the "Case" value...it won't always be "Case". The format will always be ContextPath + / + pageName and what I need is the pageName without the .html.
String uri = "/Servlet/Case.html"; int lastSlashIndex = url.lastIndexOf('/'); int lastDotIndex = url.lastIndexOf('.'); String name = uri.substring(lastSlashIndex, lastDotIndex);
Good luck.
Eric Martin
Greenhorn
Joined: Jul 15, 2005
Posts: 22
posted
0
Much more elegant than what I had =)
I just had to change: String name = uri.substring(lastSlashIndex, lastDotIndex); to: String name = uri.substring(lastSlashIndex + 1, lastDotIndex);