首页 > 其他 > 详细

String常用方法

时间:2017-09-27 00:18:11      阅读:260      评论:0      收藏:0      [点我收藏+]

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

String常用方法

原文:http://www.cnblogs.com/cyany/p/7599469.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!