js-String

1.一个字符串可以使用单引号或双引号

2.查找

字符串使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置

如果没找到对应的字符函数返回-1

lastIndexOf() 方法在字符串末尾开始查找字符串出现的位置。

3.length长度

4.内容匹配

match()函数用来查找字符串中特定的字符,并且如果找到的话,则返回这个字符。

5.替换内容

replace("","") 方法在字符串中用某些字符替换另一些字符。

6.字符串大小写转换

字符串大小写转换使用函数 toUpperCase() / toLowerCase()

7.字符串转为数组

字符串使用split()函数转为数组:

txt="a,b,c,d,e"   // String
txt.split(",");   // 使用逗号分隔

8.常用字符串属性和方法

属性:

  • length
  • prototype
  • constructor

方法:

  • charAt()
  • charCodeAt()
  • concat()
  • fromCharCode()
  • indexOf()
  • lastIndexOf()
  • match()
  • replace()
  • search()
  • slice()
  • split()
  • substr()
  • substring()
  • toLowerCase()
  • toUpperCase()
  • valueOf()
原文地址:https://www.cnblogs.com/huoran1120/p/5977977.html