[英]JavaScript-How To Separate Path from File Name
I need to separate the file path from the file name: (some codes did not work in the past) If the path is www.example.com/hi/test/home.html How would I get just www.example.com/hi/test/ ?我需要将文件路径与文件名分开:(过去某些代码不起作用)如果路径是www.example.com/hi/test/home.html我将如何获得www.example.com/嗨/测试/ ?
You can use substring
and lastIndexOf
:您可以使用substring
和lastIndexOf
:
a = "www.example.com/hi/test/home.html";
b = a.substr(0, a.lastIndexOf('/'));
// b = www.example.com/hi/test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.