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.

1 comment:

  1. Good post and I like it very much. By the way, anybody try this app development company for iOS and Android? I find it is so professional to help me boost app ranking and increase app downloads.