首页 > Web开发 > 详细

js去除字符串空格

时间:2015-03-09 12:26:32      阅读:295      评论:0      收藏:0      [点我收藏+]
str.replace(/\s+/g,"");
str.replace(/\s|\xA0/g,"");

 

empName=empName.replace(/^\s+/g,"");       //去左
empName=empName.replace(/\s+$/g,"")        //去右
empName=empName.replace(/(^\s*)|(\s*$)/g, ""); //去左右

 

//去除空格 
String.prototype.Trim = function() { 
    return this.replace(/\s+/g, ""); 
} 
     
//去除换行 
function ClearBr(key) { 
    key = key.replace(/<\/?.+?>/g,""); 
    key = key.replace(/[\r\n]/g, ""); 
    return key; 
} 
     
//去除左侧空格 
function LTrim(str) { 
    return str.replace(/^\s*/g,""); 
} 
     
//去右空格 
function RTrim(str) { 
    return str.replace(/\s*$/g,""); 
} 
     
//去掉字符串两端的空格 
function trim(str) { 
    return str.replace(/(^\s*)|(\s*$)/g, ""); 
} 
     
//去除字符串中间空格 
function CTim(str) { 
    return str.replace(/\s/g,‘‘); 
}  

 

js去除字符串空格

原文:http://www.cnblogs.com/linguoguo/p/4277890.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!