Bee AntWongjorie's Blog

FE前端

BE后端

DB数据库

OPS运维

Snippet代码片段

Note笔记

I'm also on

GithubIf you code

MailIf you talk

RSSIf you subscribe

Trim snippet


高效移除字符串开始和末尾的空格

  String.prototype.trim = function() {
    var str = this.replace(/^\s+/, "");
          end = str.length - 1;
          ws = /\s/;

    while(ws.test(str.charAt(end))) {
      end--;
    }

    return str.slice(0, end+1);
  }