zoukankan      html  css  js  c++  java
  • string 去除空格

     

      

    /**
     * 去除空格
     * @param  {str}
     * @param  {type} 
     *       type:  1-所有空格  2-前后空格  3-前空格 4-后空格
     * @return {String}
     */
    trim (str, type) {
        type = type || 1
        switch (type) {
            case 1:
                return str.replace(/s+/g, "");
            case 2:
                return str.replace(/(^s*)|(s*$)/g, "");
            case 3:
                return str.replace(/(^s*)/g, "");
            case 4:
                return str.replace(/(s*$)/g, "");
            default:
                return str;
        }
    }
  • 相关阅读:
    java 28
    java 28
    java 27
    java 27
    java 27
    java 27
    java 27
    java 27
    java 27
    java 27
  • 原文地址:https://www.cnblogs.com/Enid0044/p/8473430.html
Copyright © 2011-2022 走看看