JS 小筆記 字串

2021-08-22 07:07:45 字數 660 閱讀 6286

字串操作:

1. 獲得字串的長度

var browsertype = 'mozilla';

browsertype.length;

2. 檢索特定字串字元

browsertype[0];
3. 在字串中查詢子字串並提取它

browsertype.indexof('zilla');
下面用法 !== 和  -1 雙重否定表示肯定,即是判斷字串是否存在mozilla字元段。 

if(browsertype.indexof('mozilla') !== -1)
4.當你知道字串中的子字串開始的位置,以及想要結束的字元時,slice()可以用來提取 它。(切片)

browsertype.slice(0,3);
第一引數表示第幾位開始(計算機從0開始算第一位),第二個引數表示有幾個。

當只有乙個引數是只代表第乙個引數。

5.轉換大小寫

字串方法tolowercase()touppercase()字串並將所有字元分別轉換為小寫或大寫。 

js筆記字串

獲取 字串.charat 位置 字串.charcodeat 位置 獲取字串的編碼 string.fromcharcode 編碼 把編碼變為字串 查詢 字串.indexof 字串第一次出現的位置 search 與indexof功能相當相容正則 字串.lastindexof 字串從最後開始第一次出現的位...

JS筆記 字串

charat 語法 string.charat index 功能 返回string中index位置的字元 let str hello world console.log str 1 e console.log str.charat 0 h console.log str.charcodeat 4 1...

python小筆記 字串

單引號或者雙引號括起來的任意文字 建立 str sunck good 運算 字串連線 str1 sunck str2 good str3 str1 str2 print str3 str3 返回str3 sunck good 輸出重複的字串 str1 good str2 str1 3 print s...