Posted By

TopcatSoftware on 01/09/11


Tagged

trim


Versions (?)

single space a string in javascript


 / Published in: JavaScript
 

URL: http://www.topcat.hypermart.net/index.html

small handy snippet to single space a string in javascript

  1. // single space a string in javascript - Topcat Software LLC - 2010
  2. // http://www.topcat.hypermart.net/index.html
  3. // before: str = " when harry met sally "
  4. // after: str = "when harry met sally"
  5.  
  6. str.replace(/^\s+|\s+$/g,'').replace(/\s\s+/g,' ')

Report this snippet  

You need to login to post a comment.