1 拼接
Concat():拼接字符串
Let stringvalue = “hello ”;
Let result = stringvalue.concat(“world”)
Console.log(result) // “hello world”
2 删
Let stringvalue = “hello world”
Console.log(stringvalue.slice(3)); // ‘lo world’
Console.log(stringvalue.substring(3)); //lo world
Console.log(stringvalue.substr(3,7) // lo worl
3 改
trim(),trimLeft(),trimRight():删除首尾空白
二、转换方法
split():按分隔符拆分字符串为数组
Let str = “12+23+34”
Let arr = str.split(“+”) // [12,23,34]
三、模版匹配方法
与正则表达式配合使用的方法
match()
返回匹配正则表达式的数组
Let str = “cat,bat,sat”
Let pattern = “/.at/”;
Let matches = text.match(pattern);
Console.log(matches[0]); //“cat”
Search()
返回匹配正则表达式的索引或-1
Let text = “cat,bat,sat,fat”
Let pos = text.search(/at/)
Console.log(pos) //1
Replace():替换匹配正则表达式的内容
Let text = “cat,bat,sat,fat”
Let result = text.replace(“at”,”ond”)
Console.log(result) // “cond,bat,sat,fat”