Browse - programming tips - javascript trim spaceDate: 2010mar26 Language: javaScript A. How can I remove leading and trailing space from a string in javaScript? 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 + '<'); }
Add a commentSign in to add a comment | Advertisements:
|