JS String對象方法

來源:互聯網
上載者:User

標籤:

charAt  返回指定索引位置處的字元  str.charAt(index);charCodeAt 返回一個整數,代表指定位置上字元的 Unicode 編碼。 str.charCodeAt(index)concat 返回字串值,該值包含了兩個或更多個提供的字串的串連。 str.concat(str1,str2);fromCharCode  從一些 Unicode 字元值中返回一個字串。String.fromCharCode(100,101,102);//defindexOf  返回 String 對象內第一次出現子字串的字元位置。  str.indexOf(‘test‘);lastIndexOf  返回 String 對象中子字串最後出現的位置。  str.lastIndexOf(‘test‘);match   使用Regex模式對字串執行尋找,並將包含尋找的結果作為數組返回。         str.match(rgExp);             var r, re;         // 聲明變數。           var s = "The rain in Spain falls mainly in the plain";            re = /ain/i;    // 建立Regex模式。           r = s.match(re); replace  返回根據Regex進行文字替換後的字串的複製。 str.replace(‘t‘,‘a‘);        如果不使用Regex,則只能替換一個,使用Regex才能全部替換          var r, re;                    // 聲明變數。            var ss = "The man hit the ball with the bat.\n";             ss += "while the fielder caught the ball with the glove.";             re = /The/g;             // 建立Regex模式。             r = ss.replace(re, "A");    // 用 "A" 替換 "The"。search  返回與Regex尋找內容匹配的第一個子字串的位置。 str.search(‘t‘);     var r, re;                   // 聲明變數。        var s = "The rain in Spain falls mainly in the plain.";        re = /falls/i;            // 建立Regex模式。        r = s.search(re);            // 尋找字串。slice 返回字串的片段。 str.slice(start,end);split 將一個字串分割為子字串,然後將結果作為字串數組返回。 str.split(‘==‘);          var s, ss;            var s = "The rain in Spain falls mainly in the plain.";           // 在每個空白字元處進行分解。            ss = s.split(" ");substr  返回一個從指定位置開始的指定長度的子字串。str.substr(start [, length ])        str.substr(5,12);從5開始長度12substring  返回位於 String 對象中指定位置的子字串。 str.substring(start, end);toLowerCase  返回一個字串,該字串中的字母被轉換為小寫字母。  str.toLowerCase( )toUpperCase  返回一個字串,該字串中的所有字母都被轉化為大寫字母。 str.toUpperCase( )toString   返回對象的字串表示。 obj.toString([radix])        radix 可選項。指定將數字值轉換為字串時的進位。        

 

JS 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.