js之字符串

  • 字符串

1.内置对象
在JavaScript中已经定义好的对象

比较常用的 JavaScript 内置对象主要有以下几种:
(1)字符串对象 String;
(2)日期对象 Date;
(3)数组对象 Array;
(4)数值对象 Math 和 Number;

2.字符串属性 : length
可以用来获取字符串的长度

  • 处理字符串的方法(11种)
(1)match():查询字符串中字符串是否存在,存在就输出
			var str1='java c++ c# python html css';
			alert(str1.length);  获取字符串的长度
			document.write(str1.match('python'));	
			返回null值: 表示没有查询到love
			document.write(str1.match('Python')); 

			(2)search():检索字符串中字符所在的索引,返回索引值
			document.write(str1.search('Sc'));
			
			(3)indexOf():返回元素在在字符串中第一次出现的索引
			document.write(str1.indexOf('a'));
			
			(4)replace():在字符串中用一些字符替换另外一些字符
			document.write(str1.replace('JavaScript','InLett'));

			(5)charAt():获取字符串中制定字符
			document.write(str1.charAt(3));
			
			(6)大小写转换:tolowerCase()和toUpperCase()
			document.write(str1.toLowerCase());
			document.write(str1.toUpperCase());

			(7)concat():链接字符串
			document.write(str1.concat(',HTML',',CSS'));
			
			(8)比较字符串localeCompare(): 根据ASCII表的排列进行比较
			var str2='java c++ c# python html css';
			document.write(str2.localeCompare('avaScript'));
			
			(9)split():分割字符串(分割符是以字符串中的字符进行分割)  返回一个数组
			var arr=new Array();
			arr=str2.split(',');
			document.write(arr);
			document.write(arr[0]);
			document.write(arr[1]);
			
			(10)subString(start,end):截取字符串
			var str3='java c++ c# python html css';
			不包含结束的索引对应的值 
			document.write(str3.substring(0,2));
			document.write(str3.substring(3,38));
			
			document.write(str3.substring(4,2));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值