Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get a part of URL in string in Java

Let assume there is a string such as "https://testdomain.com/12345/testdocument.pdf"

I need only "testdocument.pdf" part.

Important part is, there is no exact location. Character size can be changed but needed part will always be at the end of string

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Anyone can help me?

>Solution :

If you are sure that the needed part will be after the last ‘/’ character, then what you can do is

String url = "https://testdomain.com/12345/testdocument.pdf";
String neededPart = url.substring(url.lastIndexOf("/") + 1);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading