I have a String like this
String str = "www.google.com/..../upload/FileName.zip
I want to extract the string "FileName" from above string. I tried substr() method but couldn't found any solution.
I have a String like this
String str = "www.google.com/..../upload/FileName.zip
I want to extract the string "FileName" from above string. I tried substr() method but couldn't found any solution.
 
    
     
    
    You can try this
    String str = "www.google.com/..../upload/FileName.zip";
    File file=new File(str);
    String fileName=file.getName();// now fileName=FileName.zip
    System.out.println(fileName.split("\\.")[0]);
Out put:
    FileName
 
    
    Is it what you are looking for ?
  String lastPart= yourUrl.substring(yourUrl.lastIndexOf('/')+1, yourUrl.length());
  String fileName = lastPart.substring(0, lastPart.lastIndexOf('.'));
Considering the given format won't change.
 
    
    To get the part between the last slash and the dot:
String filename = str.replaceAll(".*?(?:/(\\w+)\\.\\w+$)?", "$1");
This regex has some special sauce added to return a blank if the target isn't found, by making the target optional and the leading expression reluctant.
 
    
    Try this
String str = "www.google.com/..../upload/FileName.zip";
    String  str1[] = str.split("/");
    String file=str1[str1.length-1];
    String fileName=file.substring(0, file.lastIndexOf("."));
    System.out.println(fileName);
Output
FileName
