Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

去除字符串空格 #52

Open
Sunny-117 opened this issue Nov 3, 2022 · 0 comments
Open

去除字符串空格 #52

Sunny-117 opened this issue Nov 3, 2022 · 0 comments

Comments

@Sunny-117
Copy link
Owner

var str = ' as '
//方法1
str = str.replace(/\s*/g,"");//去除所有空格
str = str.replace(/^\s*|\s*$/g,"");//去除两头空格
str = str.replace(/^\s*/,"");//去除左边空
str = str.replace(/(\s*$)/g,"");//去除右边空格
//方法2:trim()方法:只能去除两边空格
function trim(str) {
  if (str && typeof str === "string") {
    return str.replace(/(^\s*)|(\s*)$/g, "");//去除前后空白符
  }
}
//方法3 jquery $.trim(str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant