function trim(s) { return s.replace(/^\s*|\s*$/g,"") }
據說這個版本更快:
// Author: Ariel Flesler // http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html // Licensed under BSD function myBestTrim(str) { var start = -1, end = str.length; while (str.charCodeAt(--end) < 33); while (str.charCodeAt(++start) < 33); return str.slice(start, end + 1); };
Refrence:
http://jsgears.com/thread-132-1-1.html
http://www.ijavascript.cn/jiaocheng/javascript-trim-145.html
沒有留言:
張貼留言