single space a string in javascript


/ Published in: JavaScript
Save to your folder(s)

small handy snippet to single space a string in javascript


Copy this code and paste it in your HTML
  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,' ')

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.