<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## String 對象 String對象是JavaScript提供的原生數據類型的包裝對象,用來生成字符串的包裝對象。 String對象的方法也可以在基本的字符串值中訪問到。 ~~~javascript var s = "hello"; var ss = new String("hello"); console.log(typeof ss); // object console.log(String(true)); // true console.log(String(123)); // 123 ~~~ ## 1.String對象的屬性和方法 `length`屬性:返回字符串的長度 `charAt()`方法:返回指定位置的字符,參數從0開始編號 `concat()`方法:用于連接兩個字符串,返回一個新的字符串,不改變原字符串 `slice()`方法:用于從原字符串中取出子字符串,并返回,不改變原字符串 `substring()`方法:用于從原字符串取出子字符串,并返回,不改變原字符串。與slice作用相同,但有些奇怪的規則,不建議使用 `substring`,優先使用 `slice`。 `indexOf()`和`lastIndexOf()`:確定一個字符串在另一個字符串中的位置,返回一個整數,表示匹配開始的位置。如果返回-1表示沒有匹配到。`indexOf`是從頭部開始匹配,`lastIndexOf`是從尾部開始匹配。 `trim()`:去除字符串兩端的空格,返回一個新的字符串,不改變原字符串 `substr()`:方法用于從原字符串中取出子字符串并返回,不改變原字符串,接受兩個參數,第一個參數是子字符串開始位置,第二個參數是子字符串的長度。 `toLowerCase()`、`toUpperCase()`:將字符串全部改為小寫或者大寫,返回一個新的字符串,不改變原來字符串。 `search()`:返回匹配的第一位置,沒有找到返回-1 `replace()`:該方法用于替換匹配的字符串,一般情況下只匹配第一個匹配到的元素 `split()`:按照給定字符分割字符串,并返回一個由分割字符串分割出來的子字符串數組。 `match()`:對字符串進行正則匹配,返回匹配結果。 示例 ~~~javascript var s = "hello"; var ss = new String("hello"); console.log(typeof ss); // object console.log(String(true)); // true console.log(String(123)); // true console.log("s.length=" + s.length); // 5 console.log(s.charAt(0)); // h console.log(s[0]); // h console.log(s.concat(",world!")); // hello,world! console.log(s); // hello var s2 = "javascript"; console.log(s2.slice(4,10)); // script console.log(s2.slice(4)); // script console.log(s2.indexOf("a")); // 1 console.log(s2.lastIndexOf("a")); // 3 console.log(s2.lastIndexOf("y")); // -1 var s3 = "aa.bb.cc.txt"; console.log(s3.slice(s3.lastIndexOf(".")+1)); // txt var s4 = " aa.bb.cc.txt "; console.log(s4.trim()); var s5 = "hello,world,world!"; console.log("substr():" + s5.substr(6,5)); // world console.log("toLowerCase():" + s5.toLowerCase()); // hello,world console.log("toUpperCase():" + s5.toUpperCase()); // HELLO,WORLD console.log("search():" + s5.search("lll")); // -1 console.log("replace():" + s5.replace("world","nantong")); // hello,nantong,world var s6 = ",aa,bb,cc,dd,"; console.log(s6.split(",")); // ["","aa","bb","cc","dd",""] ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看