indexOf和replace的用法及案例

来源:互联网 发布:平板看电视直播软件 编辑:程序博客网 时间:2024/05/23 01:24
indexOf用法 :
var str = "abcdefg"
str.indexOf("a")    // 0
//如果不存在会返回 -1
//如果存在会返回该字符在字符串中的位置1234


replace用法 :
var str = "a b c d"
str.replace("a", "x") 
cc.log(str)
// "a b c d"1234var str = "a b c
0 0