Get value of a string after last slash in JavaScript

前端 未结 10 1430
感情败类
感情败类 2020-11-29 19:05

I am already trying for over an hour and cant figure out the right way to do it, although it is probably pretty easy:

I have something like this : foo/bar/test

10条回答
  •  孤独总比滥情好
    2020-11-29 19:22

    String path ="AnyDirectory/subFolder/last.htm";
    int pos = path.lastIndexOf("/") + 1;
    
    path.substring(pos, path.length()-pos) ;
    

    Now you have the last.htm in the path string.

提交回复
热议问题