String常用方法
阿新 • • 發佈:2017-09-27
exp 常用 char -h 查看 school cond 分享 根據
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常用方法