Home > Web Front-end > JS Tutorial > body text

JS enhanced version to remove spaces from strings (can remove spaces in the middle)_javascript skills

WBOY
Release: 2016-05-16 18:47:37
Original
877 people have browsed it

javascript trim space removal function implementation code
http://www.jb51.net/article/16250.htm

The following is the enhanced version

Copy code The code is as follows:

// Function: 1) Remove all spaces before and after the string
// 2) Remove characters All spaces in the string (including spaces in the middle, you need to set the second parameter to: g)
function Trim(str,is_global)
{
var result;
result = str.replace(/( ^s )|(s $)/g,"");
if(is_global.toLowerCase()=="g")
result = result.replace(/s/g,"");
return result;
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template