字符串的方法

字符串方法
        // toUpperCase()转大写==toLocaleUpperCase()
        // toLowerCase()转小写==toLocaleLowerCase()

var a = "abcdefg";
		// var b = "ABCDEFG";
		// console.log(a.toUpperCase());
		// console.log("Hello Word".toUpperCase());
		// console.log(b.toLowerCase());
		// console.log("Hello Word".toLowerCase());
		// console.log(a.toLocaleUpperCase());
		// console.log(b.toLocaleLowerCase());

concat("连接的字符串")连接字符串

var a = "hello";
		// var b = a.concat("word");
		// console.log(b);

 indexOf()查询某个字符串在原字符串中首次出现的位置(下标)
        // 如果查询不到值是否存在返回-1

var a = "hello word";
		// var b = a.indexOf("o");
		// var b = a.indexOf("r");
		// var b = a.indexOf("a");
		// var b = a.indexOf("b");
		// var b = a.indexOf("c");
		// console.log(b);
		// var str = "hasdjhsa张三jsdjklasjdshfjksakha";
		// if(str.indexOf("张三")==-1){
		// 	console.log("没有查询到张");
		// }else {
		// 	console.log("查询到了");
		// 	console.log(str.indexOf("张三"));
		// 	var a = str.indexOf("张");
		// 	console.log(str[a]);
		// }

charAt(下标)查找下标所在位置对应的字符

var a = "hello word";
		// // var b = a.lastIndexOf("o");
		// var b = a.lastIndexOf("a");
		// console.log(b);

replace(原字符串需要替换的值,新的值)
        // 替换字符串首次出现的字符,不会修改原字符串

var a = "hello word";
		// var b = a.replace("o","p");
		// var b = a.replace("word","Job");
		// console.log(b);
		// console.log(a);

substring(起始下标,结束下标),截取字符串,[起始下标,结束下标)
        // substr(起始下标,截取长度)截取字符串

split()切割字符串,会变成数组

var a = "hello word";
		// var data = "2023-03-16";
		// var b = a.split("o");
		// var b = data.split("-");
		// console.log(b);

trim()清除字符串前后空格

 var a = "    abc    ";
		// var b = a.trim();
		// a = a.trim();
		// console.log(b);
		// console.log(a);

isNaN(检测字符串是否为数字字符串)
        // 判断字符串是否为数字字符串,true表示不是,false表示是

var a = "abc";
		// var b = isNaN(a);
		// console.log(b);
		// console.log(isNaN("abc"));
		// console.log(isNaN("123"));

slice(起始下标,结束下标),截取字符串

slice()==substring()
		// var a = "hello word";
		// var b = a.slice(4,7);
		// console.log(b);

charCodeAt(下标)输出ascll码(键盘2进制值)使用很少

var a = "Ehello word";
		// var b = a.charCodeAt(2);
		// var c = a.charCodeAt(0);
		// console.log(b);
		// console.log(c);

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值