String.prototype.deletSpace = function(){
var str = this;//提取需要操作的字符串
while(str[0]==" "){//删除前面的空格。
str = str.substring(1);
}
while(str[str.length-1]==" "){//删除后面的空格。
str = str.substring(0,str.length-1);
}
return str;
}
var str2 = " kljkgljsgk kljklj lkj ";
console.log("‘"+str2.deletSpace()+"‘");
String.prototype.Trim = function(){
return this.replace(/(^\s+)|(\s$)/g,"")
}
console.log(str2.Trim());
原文地址:https://www.cnblogs.com/studyh5/p/9785452.html
时间: 2024-10-09 02:23:04