JavaScript String原生類型的擴充

來源:互聯網
上載者:User

String原生類型
 String.prototype
  --length:獲得字串的長度
  --charAt(pos):獲得當前位置的字元(串)
  --indexOf(str,position):尋找字串
  --lastIndexOf(str,position):從後尋找字串
  --match(regexp):使用Regex檢驗字串
  --replace(search,replaceValue):替換字串
  --search(regexp):在字串搜尋某個子串
  --toUpperCase():將字串轉化為大寫
  --toLowerCase():將字串轉化為小寫
  --split(str):分割字串至數組
  --substring(start[,end])
   --得到字元子串
   --從下標start開始 ,到下標end-1為止
   --如果沒有提供end則得到start開始的所有子串
  --slice(start[,end])
   --得到字元子串
   --從下標start開始 ,到下標end-1為止
   --如果沒有提供end則得到start開始的所有子串 
   --如果start小於零,則表示倒數第n位(start+length),end亦是如此

String原生類型的擴充

 String.prototype
  --endsWith(str):返回布爾值,表示是否以某字串結尾
  --startsWith(str):返回布爾值,表示是否以某字串開始
  --trim():返回字串,去除原字串首尾空白
  --trimEnd():返回字串,去除原字串結尾空白
  --trimStart():返回字串,去除原字串起始空白
 String.format(format,arg1[,arg2[,arg3[,......]]]);
  --String.format("{0}{1}",arg1,arg2)
 String.localeFormat(format,arg1[,arg2[,arg3[,......]]]);
  --除format的功能之外,提供與當前語言環境相關的字串轉化功能

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.