js实现去除首尾空格
js实现去除首尾以及中间空格(所有空格)
复制javascript/**
* js实现去除首尾空格
* @param str
* @returns {*|void|string}
*/
function trimStr(str){
return str.replace(/(^\s*)|(\s*$)/g,"");
}
/**
* js实现去除首尾以及中间空格(所有空格)
* @param str
* @returns {*|void|string}
*/
function trimStrAll(str){
return str.replace(/\s/g,"");
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17