<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](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String "String?全局對象是一個用于字符串或一個字符序列的構造函數。") **trim**()? ? ? ? ? ?去掉字符串兩邊的空格 **charAt**() 獲取字符串指定位置的字符 ``` var str="abcdefg"; var len=str.length;//7 console.log(str.charAt(1));//b console.log(str[1]);//b ``` **charCodeAt**() 獲取字符串指定位置的Unicode編碼 ``` var str="Habcdefg"; console.log(str.charCodeAt());//72 //String.fromCharCode();根據Unicode編碼獲取字符 var str=String.fromCharCode(72) console.log(str);//H ``` **concat**(另一個字符串)? ? ?連接兩個字符串 作用和+一樣 ``` var str="你好!"; str.concat("塞北的","雪"); ``` **indexOf**("要查找的字符","查找的起始位置") 返回某個指定的字符串值在字符串中首次出現的位置。沒找到返回-1 ``` var str="aabcdefgabc"; console.log(str.indexOf("a"));//0 console.log(str.indexOf("a",1));//1 console.log(str.indexOf("a",2));//8 ``` **lastIndexOf**() 從后向前搜索字符串,并從起始位置(0)開始計算返回字符串最后出現的位置。 ``` var str="abcadefgabc"; //默認是從c開始找a在倒數第三個位置出現,他的索引位置是8 console.log(str.lastIndexOf("a"));//8 //從索引為1的位置向左找,最后的a在索引為0的位置出現 console.log(str.lastIndexOf("a",1));//0 console.log(str.lastIndexOf("a",0));//0 //從索引為5的位置(abcade)向左找,最后的a在索引為3的位置出現 console.log(str.lastIndexOf("a",5));//3 ``` **slice**(開始位置,結束位置)提取字符串的片斷,并在新的字符串中返回被提取的部分。開始位置<=value<結束位置 ``` var str="abcadefgabc"; console.log(str.slice(0,1));//a console.log(str.slice(3));//adefgabc ``` **substring**(strat,end)? 截取字符串strat<=value<end 和slice一樣不包括結束位置 區別 第二個參數不支持負數,會將負數轉為0 第一個參數大于第二個參數則他們相互交換位置 ``` var str="abcadefgabc"; str.substring(1,-1)=》str.substring(1,0)=》str.substring(0,1) console.log(str.substring(0,1));//a console.log(str.substring(3));//adefgabc ``` **substr**(start,length)? ? 截取字符串(es沒有標準化,但是瀏覽器都支持) ``` var str="abcadefgabc"; console.log(str.substr(0,1));//a console.log(str.substr(0,3));//abc console.log(str.substr(3));//adefgabc ``` **toLowerCase**()把字符串轉換為小寫。 ``` var str="abc"; console.log(str.toLowerCase());//ABC ``` **toUpperCase**()把字符串轉換為大寫。 ``` var str="ABC"; console.log(str.toUpperCase());//abc ``` ## **支持正則的** **splite**(切割符)? 將字符竄按指定的切割符分割,并返回數組(字符轉數組)與arr.join相反 ``` var str="a,b,c"; console.log(str.split(','));//[a,b,c] var str="a1b2c3e"; console.log(str.split(/[0-9]/));//["a", "b", "c", "e"] ``` **search**(string/preg)? ?從字符串中查找給定的string字符? ?找到返回第一次出現的索引位置,沒找到返回 -1? ? 注意:preg表示也可以查找正則匹配出的字符 ``` var str="123abc3e"; console.log(str.search("abc"));//3 var str="a1b2c3e"; console.log(str.search(/[0-9]/));//1 ``` **match**(string/preg)? ? 從字符串中查找給定的string(或者查找正則匹配出的字符)通過返回數組(格式為【查找的字符串,索引位置、輸入的字符串】),不存在返回null ``` var str="a1b2c3e"; console.log(str.match("b"));//["b", index: 2, input: "a1b2c3e"] var str="a1b2c3e"; console.log(str.match(/[a-z]/));//["a", index: 0, input: "a1b2c3e"] //默認值匹配一個,我們可以添加全局匹配模式g var str="a1b2c3e4F5G"; console.log(str.match(/[a-z]/g));//["a", "b", "c", "e"] var str="a1b2c3e4F5G"; console.log(str.match(/[a-z]/ig));//["a", "b", "c", "e", "F", "G"] ``` **replace**(string/preg,替換的字符)? ? ?string為被替換的字符, ``` var str ='你妹的,world'; str.replace('你妹的',"***");將你妹的替換成*** str.replace('/你妹/','**'); str.replace('/word/','**'); //默認值替換一個,我們可以添加全局匹配模式g var str="a1b2c3e4F5G"; console.log(str.replace(/[a-z]/ig,""));//12345 var str="a1b2c3e4F5G"; console.log(str.replace(/[a-z]/ig,"^_^"));//^_^1^_^2^_^3^_^4^_^5^_^ ``` ## String 對象方法 | 方法 | 描述 | | :-- | :-- | | [charAt()](https://www.runoob.com/jsref/jsref-charat.html) | 返回在指定位置的字符。 | | [charCodeAt()](https://www.runoob.com/jsref/jsref-charcodeat.html) | 返回在指定的位置的字符的 Unicode 編碼。 | | [concat()](https://www.runoob.com/jsref/jsref-concat-string.html) | 連接兩個或更多字符串,并返回新的字符串。 | | [fromCharCode()](https://www.runoob.com/jsref/jsref-fromcharcode.html) | 將 Unicode 編碼轉為字符。 | | [indexOf()](https://www.runoob.com/jsref/jsref-indexof.html) | 返回某個指定的字符串值在字符串中首次出現的位置。 | | [includes()](https://www.runoob.com/jsref/jsref-string-includes.html) | 查找字符串中是否包含指定的子字符串。 | | [lastIndexOf()](https://www.runoob.com/jsref/jsref-lastindexof.html) | 從后向前搜索字符串,并從起始位置(0)開始計算返回字符串最后出現的位置。 | | [match()](https://www.runoob.com/jsref/jsref-match.html) | 查找找到一個或多個正則表達式的匹配。 | | [repeat()](https://www.runoob.com/jsref/jsref-repeat.html) | 復制字符串指定次數,并將它們連接在一起返回。 | | [replace()](https://www.runoob.com/jsref/jsref-replace.html) | 在字符串中查找匹配的子串, 并替換與正則表達式匹配的子串。 | | [search()](https://www.runoob.com/jsref/jsref-search.html) | 查找與正則表達式相匹配的值。 | | [slice()](https://www.runoob.com/jsref/jsref-slice-string.html) | 提取字符串的片斷,并在新的字符串中返回被提取的部分。 | | [split()](https://www.runoob.com/jsref/jsref-split.html) | 把字符串分割為字符串數組。 | | [startsWith()](https://www.runoob.com/jsref/jsref-startswith.html) | 查看字符串是否以指定的子字符串開頭。 | | [substr()](https://www.runoob.com/jsref/jsref-substr.html) | 從起始索引號提取字符串中指定數目的字符。 | | [substring()](https://www.runoob.com/jsref/jsref-substring.html) | 提取字符串中兩個指定的索引號之間的字符。 | | [toLowerCase()](https://www.runoob.com/jsref/jsref-tolowercase.html) | 把字符串轉換為小寫。 | | [toUpperCase()](https://www.runoob.com/jsref/jsref-touppercase.html) | 把字符串轉換為大寫。 | | [trim()](https://www.runoob.com/jsref/jsref-trim.html) | 去除字符串兩邊的空白 | | [toLocaleLowerCase()](https://www.runoob.com/jsref/jsref-tolocalelowercase.html) | 根據本地主機的語言環境把字符串轉換為小寫。 | | [toLocaleUpperCase()](https://www.runoob.com/jsref/jsref-tolocaleuppercase.html) | 根據本地主機的語言環境把字符串轉換為大寫。 | | [valueOf()](https://www.runoob.com/jsref/jsref-valueof-string.html) | 返回某個字符串對象的原始值。 | | [toString()](https://www.runoob.com/jsref/jsref-tostring.html) | 返回一個字符串。 |
                  <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>

                              哎呀哎呀视频在线观看