栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

String.prototype实现的一些javascript函数介绍

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

String.prototype实现的一些javascript函数介绍

复制代码 代码如下:
//String.prototype使用  

//批量替换,比如:str.ReplaceAll([/a/g,/b/g,/c/g],["aaa","bbb","ccc"])  
String.prototype.ReplaceAll=function (A,B) {  
    var C=this;  
    for(var i=0;i        C=C.replace(A[i],B[i]);  
    };  
    return C;  
};  

// 去掉字符两端的空白字符  
String.prototype.Trim=function () {  
    return this.replace(/(^[/t/n/r]*)|([/t/n/r]*$)/g,'');  
};  

// 去掉字符左边的空白字符  
String.prototype.LTrim=function () {  
    return this.replace(/^[/t/n/r]/g,'');  
};  

// 去掉字符右边的空白字符  
String.prototype.RTrim=function () {  
    return this.replace(/[/t/n/r]*$/g,'');  
};  

// 返回字符的长度,一个中文算2个  
String.prototype.ChineseLength=function()  
{   
    return this.replace(/[^/x00-/xff]/g,"**").length;  
};  

// 判断字符串是否以指定的字符串结束  
String.prototype.EndsWith=function (A,B) {  
    var C=this.length;  
    var D=A.length;  
    if(D>C)return false;  
    if(B) {  
        var E=new RegExp(A+'$','i');  
        return E.test(this);  
    }else return (D==0||this.substr(C-D,D)==A);  
};  
// 判断字符串是否以指定的字符串开始  
String.prototype.StartsWith = function(str)   
{  
    return this.substr(0, str.length) == str;  
};  
// 字符串从哪开始多长字符去掉  
String.prototype.Remove=function (A,B) {  
    var s='';  
    if(A>0)s=this.substring(0,A);  
    if(A+B    return s;  
};
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/109321.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号