js字符转处理

那几个函数的应用:

<script>
	//全局变量删不掉,而全局属性能删掉
	var a=123;
	function aa () {
		b=321;
		delete b;
	}
	aa();
	delete a;
	//console.log(a);


	var str="wo ai sanmei";
	/*构造函数模式*/
	function strobj (argument) {
		this.concats=function (argument) {
			arguments[0].concat(arguments[1]);
			console.log(arguments[1].concat(arguments[0]));
		};
		this.indexOfs=function (argument) {
			console.log(arguments[0].indexOf("o"));
		};
		this.lastIndexOfs=function (argument) {
			console.log(arguments[0].indexOf("o"));
		};

		this.trims=function (argument) {
			console.log(arguments[0].trim().length);
		};

		this.touppers=function (argument) {
			console.log(arguments[0].toUpperCase());
		};
		this.toLowers=function (argument) {
			console.log(arguments[0].toLowerCase());
		};
	}
	strobj.prototype.slices = function(argument) {
		console.log(arguments[0].slice(0,5));
	};
	strobj.prototype.substrs = function(first_argument) {
		console.log(arguments[0].substr(0,4));
	};
	strobj.prototype.substrings = function(first_argument) {
		console.log(arguments[0].substring(0,6));
	};

	/*String*/
	//charAt()  charCodeAt()

	console.log(str.charAt(0));
	console.log(str.charCodeAt(0));

	//字符串的连接 concat(),更多情况下用加号更方便
	var str1='lio';
	var li=new strobj();

	//concat连接
	li.concats(str,str1);
	//slice剪切
	li.slices(str);
	//substr从第几个选几个
	li.substrs(str);
	//substring从第几个到底几个
	li.substrings(str);

	//indexOf字符位置
	li.indexOfs(str);
	//lastIndexOf
	li.lastIndexOfs(str);

	//trim 删除空格
	li.trims("  Lio ai sanmei    ");

	//大小写转换
	li.touppers(str);
	li.toLowers(str);

//字符串匹配

</script>



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值