<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ``` ~~~ /* * 在JS中用單引號、雙引號、反引號包起來的都是字符串:每一個字符串都是由零到多個字符組成的,和數組類似,每一個字符也都有自己的索引 * 索引0 -> 'w' * 索引1 -> 'e' * str.length存儲了一共有多少個字符,也就是字符串的長度 */ // let str = "welcome to zhufeng peixun!"; // console.log(str[0]); //=>基于索引獲取指定位置的字符 // 遍歷字符串中的每一個字符 // for (let i = 0; i < str.length; i++) { // console.log(str[i]); // } /* * 關于字符串中常用的方法 * 1.獲取字符串中指定位置字符的辦法 * + charAt * + charCodeAt * + String.fromCharCode * 2.字符串查找和截取 * + substr * + substring * + slice * 3.字符串轉換為數組的方法 * + split * 4.字符串查找是否包含某個字符 * + indexOf / lastIndexOf * + includes * 5.字符串替換 * + replace * 6.字符串大小寫轉換 * + toLowerCase * + toUpperCase * .... * localCompare / match / trim ... * * 記憶方式: * 1)方法的意義和作用 * 2)參數 * 3)返回值 * 字符串中無需記憶原始字符串是否改變,因為它是基本類型值,每一個操作都是直接操作值,對原始字符串不會產生任何影響(數組之所以要記住是否改變,是因為數組是對象類型,操作的是堆內存,方法的執行很可能把原始堆內存中的信息改變了,所以需要記憶原始數組是否改變) */ // console.log(String.prototype); /* * charAt([index]):根據索引獲取指定位置的字符(charAt相對于直接基于索引獲取的方式,在當前索引并不存在的情況下,字符串[索引]獲取的結果是UNDEFINED,而CHARAT獲取的結果是空字符串) * charCodeAt:在charAt的基礎上獲取指定字符的UNICODE編碼(ASCII碼表中的值) * String.fromCharCode([UNICODE編碼]):和charCodeAt對應,它是基于編碼獲取編碼前的字符 */ // let str = "welcome to zhufeng peixun!"; // console.log(str[0]); //=>'w' // console.log(str.charAt(0)); //=>'w' // console.log(str[str.length - 1]); //=>'!' // console.log(str.charAt(str.length - 1)); //=>'!' // console.log(str[str.length]); //=>undefined // console.log(str.charAt(str.length)); //=>'' // console.log(str.charCodeAt(0)); //=>119 (UNICODE編碼,也就是值的十進制編碼) // console.log(String.fromCharCode(119)); //=>'w' /* * 字符串截取 * substr(n,m):從索引n開始截取m個字符 * substring(n,m):從索引n開始,找到索引為m處(不包含m),找到部分截取到 * slice(n,m):和substring是以一樣的,兩個都是索引,只不過slice支持以負數作為索引 * * 最后的m不寫都是截取到字符串的末尾 */ // let str = "welcome to zhufeng peixun!"; // console.log(str.substr(3, 8)); //=>'come to ' // console.log(str.substring(3, 8)); //=>come ' // console.log(str.substring(3)); //=>substr&substring第二個參數不寫都是截取到末尾 str.substring(0):字符串克隆 // console.log(str.substring(-6, -3)); //=>'' substring只能支持正常的索引 // console.log(str.slice(-6, - // 3)); //=>'eix' slice支持負數索引 負數索引也可以這樣處理str.slice(str.length-6, str.length-3) => str.slice(20,23) /* * indexOf / lastIndexOf:獲取當前字符在字符串中第一次或者最后一次出現位置的索引,如果字符串中不包含這個字符,返回結果是-1 * includes 驗證是否包含某個字符 */ // let str = "welcome to zhufeng peixun!"; // console.log(str.indexOf('e')); //=>1 // console.log(str.lastIndexOf('e')); //=>20 /* if (str.indexOf('a') > -1) { // 包含字符a } */ /* if (str.includes('a')) { // 包含字符a } */ /* * toLowerCase / toUpperCase:把字符串中的字符進行大小寫轉換 */ // let str = 'Welcome To ZHUFENG!'; // console.log(str.toLowerCase()); //=>'welcome to zhufeng!' // console.log(str.toUpperCase()); //=>'WELCOME TO ZHUFENG!' /* * split:和數組中的join方法對應,它是把字符串,按照指定的分隔符號,拆分成數組中的每一項,返回結果是一個數組 */ // let arr = [10, 20, 30, 40]; // let str = arr.join('|'); // // console.log(str); //=>'10|20|30|40' // console.log(str.split('|')); //=>["10", "20", "30", "40"] // let str = "welcome to zhufeng peixun"; // console.log(str.split(' ')); //=>以空格拆分 ["welcome", "to", "zhufeng", "peixun"] // console.log(str.split( // '')); //=>不指定任何分隔符 ["w", "e", "l", "c", "o", "m", "e", " ", "t", "o", " ", "z", "h", "u", "f", "e", "n", "g", " ", "p", "e", "i", "x", "u", "n"] // let str = '10|'; // console.log(str.split('|')); //=>["10", ""] /* * replace(原始字符,新字符):把字符串中原始字符替換成為新字符,在不使用正則的情況下,每次執行replace只能替換一個 */ // let str = 'zhufeng2020zhufeng2021'; // str = str.replace('zhufeng', '珠峰'); // str = str.replace('zhufeng', '珠峰'); // console.log(str); //=>'珠峰2020珠峰2021' // str = str.replace('zhufeng', 'zhufengpeixun'); // str = str.replace('zhufeng', 'zhufengpeixun'); // console.log(str); //=>'zhufengpeixunpeixun2020zhufeng2021' 很多時候即使執行多次也不一定能夠實現最后的效果,所以replace一般都是伴隨正則出現的 // str = str.replace(/zhufeng/g, 'zhufengpeixun'); // console.log(str); //=>'zhufengpeixun2020zhufengpeixun2021' ~~~ ```
                  <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>

                              哎呀哎呀视频在线观看