• js的String.prototype


    (^\s+)|(\s+$)/g
    / pattern /g
    是js正则字符串的语法

    g (全文查找出现的所有 pattern)
    i (忽略大小写)
    m (多行查找)

    String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,"")}
    String.prototype.ltrim = function(){ return this.replace(/^\s+/g,"")}
    String.prototype.rtrim = function(){ return this.replace(/\s+$/g,"")}


    //批量替换,比如: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<A.length;i++) {     

            C
    =C.replace(A[i],B[i]);     

        };     

       
    return C;     

    };     

    // 返回字符的长度,一个中文算2个
    String.prototype.ChineseLength=function()
    {
        return this.replace(/[^\x00-\xff]/g,"**").length;
    }
    // 判断字符串是否以指定的字符串结束
    String.prototype.EndsWith = function(str)
    {
        return this.substr(this.length - str.length) == str;
    }
    // 去掉字符左端的的空白字符
    String.prototype.LeftTrim = function()
    {
        return this.replace(/(^[\\s]*)/g, "");
    }
    // 去掉字符右端的空白字符
    String.prototype.RightTrim = function()
    {
        return this.replace(/([\\s]*$)/g, "");
    }
    // 判断字符串是否以指定的字符串开始
    String.prototype.StartsWith = function(str)
    {
        return this.substr(0, str.length) == str;
    }
    // 去掉字符两端的空白字符
    String.prototype.Trim = function()
    {
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }

  • 相关阅读:
    EUI组件之DataGroup
    EUI组件之CheckBox
    EUI组件之Button
    EUI组件之BitmapLabel 位图字体
    微信小游戏 egret.getDefinitionByName获取不到
    微信小游戏横屏设置
    本地 win7 与虚拟机Centos7 ping互通和Centos7 上网设置
    Centos7没有ETH0网卡
    Parallels Desktop Centos 设置IP
    2.用Python套用Excel模板,一键完成原亮样式
  • 原文地址:https://www.cnblogs.com/zwbgreat/p/2862720.html
Copyright © 2020-2023  润新知