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()