String常用方法

1.length 查看字符串的长度

 

2.indexOf()查看对应字符的索引值

 3.lastIndexOf() 从后面开始查找,返回索引值

4.search() 查看包含字符的索引值

eq:

  • The search() method cannot take a second start position argument.
  • The search() method can take much more powerful search values (regular expressions).

5.slice() 切割字符串

5.substring() 返回字符串片段 效果和slice几乎一样,但是不允许索引值为负数

6.substr()返回切割字符串的部分

7.replace() 代替字符串,可使用正则表达式

8.concat() 合并字符串,可以同时合并多个字符串

 

 9.charAt()根据索引值找到对应的字符

10.charCodeAt() 返回对应字符的Unicode编码

 

 11.split() 将字符串转为数组

完整的方法参考:https://www.w3schools.com/jsref/jsref_obj_string.asp

posted @ 2017-09-26 22:54  cyany_blue  阅读(155)  评论(0编辑  收藏  举报