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

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

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

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

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

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

相关文章
相关标签/搜索