Return to Snippet

Revision: 38867
at January 9, 2011 04:59 by TopcatSoftware


Initial Code
// single space a string in javascript - Topcat Software LLC - 2010
// http://www.topcat.hypermart.net/index.html
// before: str = "          when    harry met        sally  "
// after:  str = "when harry met sally"

str.replace(/^\s+|\s+$/g,'').replace(/\s\s+/g,' ')

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

Initial Description
small handy snippet to single space a string in javascript

Initial Title
single space a string in javascript

Initial Tags


Initial Language
JavaScript