SaikoTroid
Thursday, November 3, 2011
String trimming in Javascript
Here is a simple trim function to remove leading and trailing whitespaces.
function trim(s) {
return s.replace(/^\s*|\s*$/g, '');
}
and in CoffeeScript
trim = (s) ->
s.replace /^\s*|\s*$/g, ''
You can check
Steven Levithan's collection of trim functions
.
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)