String 常用方法

// 不会改变原字符串
string.substring(startIndex, endIndex) —— 根据头尾位置返回一个字符串 string.substr(startIndex, length) —— 根据头位置与长度返回一个字符串 string.indexOf(
"s",index) —— 从字符串头部开始,返回某字符在字符串中的索引,第二个参数指定从哪个索引开始检索 string.lastIndexOf("s",index) —— 从字符串尾部开始,返回某字符在字符串中的索引,第二个参数指定从哪个索引开始检索 string.match(pattern) —— 字符串根据正则返回数组 string.search(pattern) —— 字符串根据正则返回第一个匹配项的索引 string.replace(oldstring.newstring) —— 只替换第一个符合的,如果替换全部则第一个参数需要使用正则

 

posted @ 2018-03-23 10:28  Mr.方  阅读(222)  评论(0编辑  收藏  举报