學習筆記:javascript內建對象:字串對象

來源:互聯網
上載者:User

標籤:ima   cto   sea   from   min   開始   str   soft   沒有   

1.字串的建立
 var str = "Hello Microsoft!";  
2.字串屬性
 constructor  返回建立字串屬性的函數 length   返回字串的長度 prototype  允許您向對象添加屬性和方法  
3.字串方法
  - (1)charAt() —-返回字串在下標index位置的字元 
  1. stringObject.charAt(index)  // 如果參數index不在0與字串長度之間,則返回一個空的字串 
  2. ‘kdfjrjrtj‘.charAt(3);  //  ====>返回 ‘j‘;
  - (2) charCodeAt() —- 返回字串相應下標index位置的字元的unicode編碼 
  1. stringObject.charCodeAt(index)  // 返回unicode編碼
  2. ‘sjdlfkjsrf‘.charCodeAt(3);  // 108  (‘l‘的unicode編碼為108)
  - (3) indexOf() —-返回某個指定的字串值在字串中首次出現的位置 
  1. stringObject.indexOf(searchvalue,fromindex); // searchvalue為需要搜尋的子字串,fromindex為從某個下標開始查詢
  2. ‘hello world!‘.indexOf(‘lo wo‘);  // 3 (子字串首次出現的位置)
  - (4) match() —- 在字串內檢索指定的值,或找到一個或多個Regex的匹配 
  1. stringObject.match(regexp)  // regexp為匹配子字串的Regex
  2. var str = ‘hello world , l love the world‘;
  3. str.match(/world/g);    //  [world, world]
  - (5) replace()--需要替代的字串 
  1. var str = ‘hello world , l love the world‘;
  2. str.replace(/world/g,‘java‘);  // "hello java , l love the java"
  3. // 其中str並沒有被改變
  

 

   

學習筆記:javascript內建對象:字串對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.