关于indexof和substring经常记不住的点

indexof 找到的字符位置是 字符串从0位开始算起的。

lastIndexOf也一样,http://localhost:8080/aaa,的lastIndexOf("/")是21位。

substring(0,a)截取的是,从0位开始算起的,直到第(a-1)位字符,不包含a位字符,例如:

var str = "http://localhost:8080/aaa";

substring(0,str.lastIndexOf("/"))得到的是"http://localhost:8080"。

原文地址:https://www.cnblogs.com/samwang88/p/7076455.html