javascript学习之日期 字符串(19)—— 字符串 常用方法(下)

1、substr(index1,index2)

substr(index1,index2) 第一个参数表示截取的起始索引,第二个参数表示截取的字符的个数

示例代码:

var ss="hello word 好好学习 abc123";
alert(ss.substr(5,5));

效果图:
javascript学习之日期 字符串(19)—— 字符串 常用方法(下)_第1张图片

2、substring(index1,index2)

substring(index1,index2)第一个参数表示起始截取的位置,第二个参数表示截取的结束位置(不包含结束位置的字符,到结束位置的前一位)

var ss="hello word 好好学习 abc123";
alert(ss.substring(5,15));

效果图:
javascript学习之日期 字符串(19)—— 字符串 常用方法(下)_第2张图片

3、match()

match() 以数组的形式返回,数组中是str中第一个和”hello”匹配的字符串

示例代码:

            var str="hello world,hello test";
             alert(str.match("hello"));

结果:
javascript学习之日期 字符串(19)—— 字符串 常用方法(下)_第3张图片

4、search()

search() 第一次出现的起始位置

示例代码:

var str="hello world,hello test";
alert(str.search("hello"));

结果:
javascript学习之日期 字符串(19)—— 字符串 常用方法(下)_第4张图片

5、replace()

replace()默认替换第一个,原有字符串不变

var str="hello world,hello test";
alert(str.replace("hello","replace"))

效果图:
javascript学习之日期 字符串(19)—— 字符串 常用方法(下)_第5张图片

6、split()

split()切割字符串

              var str2="香蕉,苹果,菠萝,橘子";
              var arr=str2.split(",");
              alert(arr);

效果图:
javascript学习之日期 字符串(19)—— 字符串 常用方法(下)_第6张图片

7、toUpperCase()

toUpperCase()转换成大写

             var str3="abcdefg";
              alert(str3.toUpperCase());

效果:
javascript学习之日期 字符串(19)—— 字符串 常用方法(下)_第7张图片

8、toLowerCase()

toLowerCase()转换成小写

             var str4="ABCDEFG";
              alert(str4.toLowerCase());

效果:
javascript学习之日期 字符串(19)—— 字符串 常用方法(下)_第8张图片

个人微信公众号:

这里写图片描述

如果我的文章对您有帮助,微信支付宝打赏:

这里写图片描述
这里写图片描述

你可能感兴趣的:(javascript,javascript)