標籤:
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對象方法