zoukankan      html  css  js  c++  java
  • 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>



  • 相关阅读:
    动态规划算法
    Spring依赖循环
    使用JMH微基准测试
    expect介绍和使用
    autossh使用(本机记住ssh密码)
    ssh端口转发(ssh隧道)
    WSL2中的Centos8安装桌面
    Tmux Plugin Manager使用及具体插件
    Python使用os.chdir命令切换python工作目录
    python脚本要控制jenkins触发job
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/6943675.html
Copyright © 2011-2022 走看看