How to get the last segment of Uri?

How to get the last segment of Uri?

To get the last segment in one line of code, simply nest the lines above. Paths.get (URI.create (“http://base_path/some_segment/id”).getPath ()).getFileName ().toString () To get the second-to-last segment while avoiding index numbers and the potential for off-by-one errors, use the getParent () method.

How to split a URL into multiple parts?

A bit of a more modern way of working with URLs is the URL() global method. If you need to break up up the pathname, for example, a URL like https://css-tricks.com/blah/blah/blah/index.html, you can split the string on “/” characters var pathArray = window.location.pathname.split(‘/’); Then access the different parts by the parts of the array, like

How to get the last path segment in Java?

To get the second-to-last segment while avoiding index numbers and the potential for off-by-one errors, use the getParent () method. Note the getParent () method can be called repeatedly to retrieve segments in reverse order.

How to break up a URL in CSS?

If you need to break up up the pathname, for example, a URL like https://css-tricks.com/blah/blah/blah/index.html, you can split the string on “/” characters.

How to retrieve the last segment of a path?

In this example, the path only contains two segments, otherwise calling getParent ().getParent () would retrieve the third-to-last segment. If you have commons-io included in your project, you can do it without creating unecessary objects with org.apache.commons.io.FilenameUtils

How to trim the last character of a string?

The easiest method is to use the slice method of the string, which allows negative positions (corresponding to offsets from the end of the string): If you needed something more general to remove everything after (and including) the last underscore, you could do the following (so long as s is guaranteed to contain at least one underscore):