我的网址总是以数字结尾,例如:
String url = "localhost:8080/myproject/reader/add/1/";
String anotherurl = "localhost:8080/myproject/actor/take/154/";
我想提取最后两个斜杠(“/”)之间的数字。
有人知道我该怎么做吗?
最佳答案
你可以拆分字符串:
String[] items = url.split("/");
String number = items[items.length-1]; //last item before the last slash
关于Java:切片字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11197353/