zoukankan      html  css  js  c++  java
  • String 的扩展方法

    String的扩展方法
    String.prototype.方法名=function(){...}
    基础知识字符串操作和正则表达式的应用
    一、合并多个空白为一个空白
    String.prototype.resetBlank = function () {
        return this.replace(/\s+/g, " ");
    }
    二、过滤空白
    String.prototype.filterBlank = function () {
        return this.replace(/\s+/g, "");
    }
    三、除去左边空白
    String.prototype.LTrim = function () {
        return this.replace(/^\s+/, "");
    }
    四、除去右边空白
    String.prototype.RTrim = function () {
        return this.replace(/\s+$/g, "");
    }
    五、保留数字
    String.prototype.getNum = function () {
        return this.replace(/[^\d]/g, "");
    }
    六、保留字母
    String.prototype.getEn = function () {
        return this.replace(/[^A-Za-z]/g, "");
    }
    七、保留中文
    String.prototype.getCn = function () {
       return this.replace(/[^\u4e00-\u9fa5\uf900-\ufa2d]/g, "")
    }
    八、得到字节长度
    String.prototype.getRealLength = function () {
       return this.replace(/[^\x00-\xff]/g, "--").length;
    }
    九、从左截取指定长度的字串
    String.prototype.leftSlice = function (n) {
       return this.slice(0, n);
    }
    十、从右截取指定长度的字串
    String.prototype.rightSlice = function (n) {
        return this.slice(this.length - n);
    }

  • 相关阅读:
    Feature hashing相关
    损失函数(Loss Function) -1
    Android系统容量检测 —— Environment 和StatFs
    android 图像处理(黑白,模糊,浮雕,圆角,镜像,底片,油画,灰白,加旧,哈哈镜,放大镜)
    android中listview的一些样式设置
    Android代码调试报错
    珍藏40个android应用源码分享
    Android应用中菜单(Menu)的位置显示问题
    解决android4.0系统中菜单(Menu)添加Icon无效问题
    android自定义title
  • 原文地址:https://www.cnblogs.com/kuikui/p/2337348.html
Copyright © 2011-2022 走看看