Richard Chan Richard Chan - 8 months ago 47
Java Question

Simple way to remove all slashes at the end of url in java

I need to remove all slashed at the end of url,and i don't known how many slashes at the end.

for example

after removing slashe at the end

are there any simple ways like regular expression to do that.


use String.replaceAll ("\\/$", "");

The $ means that it is at the end of the String

As per @WiktorStribiżew to remove multiple slashes

use String.replaceAll ("/+$", "");