[JavaScript文法學習]全面介紹String

來源:互聯網
上載者:User

標籤:eof   rom   換行   空格   arch   方法   from   search   執行個體   

String是一串Unicode字元序列。String全域對象是用來構造字串對象或者字元序列的建構函式

文法

1. 字串的字面量文法,在ES6標準中,稱為模板字面量。具體可以參考TypeScript

2. String建構函式   String(thing) /  new String(thing)

 

逸出字元

\0  \‘  \"  \\  \n  \r  \t  \v  \b  \f  \uXXXX

 

長字串

兩種方法:

1. 使用+運算子將多個字串串連  

2. 每行末尾使用反斜線 \ 以指示字串會在下一行繼續。確保反斜線後面沒有空格或者任何除分行符號以外的字元或者縮排。

 

字串對象的方法及應用情境

1. 從字串中擷取單個字元

charAt

數組索引方式 [ ]

2. 字串比較

>  <  >=  <=

localeCompare()

3. 基底字元串和字串對象的區別

字串字面量和直接通過String方法的字串都是基底字元串,JS會自動將基底字元串轉換為字串對象。只有字串對象才能使用String對象的方法。

 

String屬性

String.prototype.constructor

String.prototype.length

String方法

靜態方法: String.fromCharCode()

執行個體方法:   String.prototype.charAt()

      String.prototype.charCodeAt()

      String.prototype.codePointAt()

      String.prototype.concat()

      String.prototype.indexOf()

      String.prototype.lastIndexOf()

      String.prototype.localeCompare()

      String.prototype.match()

      String.prototype.replace()

      String.prototype.search()

      String.prototype.split()

      String.prototype.substr()

      String.prototype.substring()

      String.prototype.toLocaleLowerCase()

      String.prototype.toLocaleUpperCase()

      String.prototype.toLowerCase()

      String.prototype.toString()

      String.prototype.toUpperCase()

      String.prototype.trim()

      String.prototype.valueOf()

 

[JavaScript文法學習]全面介紹String

聯繫我們

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