JS之常用字串處理類

2022-09-06 11:57:21 字數 1069 閱讀 9239

1

class strplay extends string26

//裁剪一定長度字串

7 cut(end=80)catch

(err)13}

14//

獲取中文字元

15cwords()catch

(err)21}

22//

json型別字串轉json

23json()catch

(err)29}

30//

去空格31

space()catch

(err)37}

38//

字元檢查

39check(rep)catch

(err)46}

47//

去html標籤

48tags()catch

(err)54}

55//

字串連線

56cat()).join(""));

61 }catch

(err)64}

65//

遍歷物件

66loop(obj,back)

74return

arr;75}

76//

是否在某個陣列中

77in_array(arr)

84});

85return

ai;86}87

//是否包含某個字串

88in_str(str)

9192 }

1 let a=new strplay("

isa test string 你好世界!");

JS常用字串處理

1 字串重複 x repeat 3 2 包含 includes 返回布林值,表示是否找到了引數字串。startswith 返回布林值,表示引數字串是否在原字串的頭部。endswith 返回布林值,表示引數字串是否在原字串的尾部。let s hello world s.startswith hello...

js 常用 字串

1.基本 原始 資料型別 number string boolean null undefined 2.引用型別 object array date function regexp string 物件 string 每乙個字串均為 string物件的乙個例項 物件 1.屬性 2.方法 函式 stri...

js常用字串方法

eg var string can you help me?方法 例子 描述結果 string.substring 2,5 擷取指定字串索引為2至5 不包括5 間的的字串 n y string.substr 2,5 從指定字串索引為2的地方擷取數量為5的字串 n you string.indexof...