user3650408 user3650408 - 8 months ago 25
Java Question

URL parse without String split

Java has cool URL parser


public class ParseURL {
public static void main(String[] args) throws Exception {

URL aURL = new URL(""
+ "/index.html?name=networking#DOWNLOADING");

System.out.println("path = " + aURL.getPath());

Here is the output displayed by the program:

path = /docs/books/tutorial/index.html

I would like to take only this part :
) Guessing don`t use string split, I am looking for other better resolution for this task.

Thank you in advance

String path = "/docs/books/tutorial/index.html";
path = path.substring(1, path.lastIndexOf("/"));

gives docs/books/tutorial