F
FAQ server
-----------------------------------------------------------------------
FAQ Topic - How do I trim whitespace?
-----------------------------------------------------------------------
A regular expression can be used:
function trimString(s) {
return s.replace(/^\s+|\s+$/g,'');
}
Implementations are inconsistent with ` \s `. For example,
some implementations do not match ` \xA0 ` (no-break space),
among others.
A more consistent approach would be to create a character class
that defines the characters to trim.
ECMAScript 5 defines ` String.prototype.trim `, but this is
not yet widely supported.
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp
http://thinkweb2.com/projects/prototype/whitespace-deviations/
https://developer.mozilla.org/en/Firefox_3.1_for_developers
http://docs.sun.com/source/816-6408-10/regexp.htm
http://msdn.microsoft.com/en-us/library/6wzad2b2(VS.85).aspx
http://groups.google.com/group/comp...39217600c3/31092c5eb99625d0?#31092c5eb99625d0
http://unicode.org/Public/UNIDATA/PropList.txt
The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/
FAQ Topic - How do I trim whitespace?
-----------------------------------------------------------------------
A regular expression can be used:
function trimString(s) {
return s.replace(/^\s+|\s+$/g,'');
}
Implementations are inconsistent with ` \s `. For example,
some implementations do not match ` \xA0 ` (no-break space),
among others.
A more consistent approach would be to create a character class
that defines the characters to trim.
ECMAScript 5 defines ` String.prototype.trim `, but this is
not yet widely supported.
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp
http://thinkweb2.com/projects/prototype/whitespace-deviations/
https://developer.mozilla.org/en/Firefox_3.1_for_developers
http://docs.sun.com/source/816-6408-10/regexp.htm
http://msdn.microsoft.com/en-us/library/6wzad2b2(VS.85).aspx
http://groups.google.com/group/comp...39217600c3/31092c5eb99625d0?#31092c5eb99625d0
http://unicode.org/Public/UNIDATA/PropList.txt
The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/