Programming Tips - javaScript: remove leading and trailing space from a string

Date: 2010mar26 Language: javaScript Q. javaScript: remove leading and trailing space from a string A. Here's a simple function that does that:
function trimSpace(str) { return str.replace(/^\s+|\s+$/g, ''); } function exampleUse() { var s; s = " \t hello \t\n"; s = trimSpace(s); alert('>' + s + '<'); }