运用正则去除空格:
//去左空格;
function lefttrim(s){
return s.replace(/(^\s*)/g, "");
}
//去右空格;
function righttrim(s){
return s.replace(/(\s*$)/g, "");
}
//去左右空格;
function trim(s){
return s.replace(/(^\s*)|(\s*$)/g, "");
}
运用正则去除空格:
//去左空格;
function lefttrim(s){
return s.replace(/(^\s*)/g, "");
}
//去右空格;
function righttrim(s){
return s.replace(/(\s*$)/g, "");
}
//去左右空格;
function trim(s){
return s.replace(/(^\s*)|(\s*$)/g, "");
}
转载于:https://www.cnblogs.com/liu-heng/p/6780235.html