码迷,mamicode.com
首页 > 其他好文 > 详细

string 去除空格

时间:2018-02-26 16:25:49      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:AC   rip   switch   java   post   div   去除   pre   ace   

/**
 * 去除空格
 * @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;
    }
}

  

string 去除空格

标签:AC   rip   switch   java   post   div   去除   pre   ace   

原文地址:https://www.cnblogs.com/Enid0044/p/8473430.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!