Article written

  • on 19.12.2009
  • at 02:37 PM
  • by admin

How to remove white spaces from a string 0

Dec19

Today at work, I happened to write a function that removes white spaces from a string. After trying different ways using: loops, array indexer, or regex, I came up with the shortest way using regular expression to share with you:

var str = ” — This is %$# ‘\’ a test string ha    hee hhhoo    1   22 33  “;
str = str.replace(/\s/g, ”);
// str is now –Thisis%$#”ateststringhaheehhhoo12233
http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/digg_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/reddit_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/stumbleupon_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/delicious_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/technorati_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/google_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/facebook_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/yahoobuzz_24.png http://iamtotti.com/blog/wp-content/plugins/sociofluid/images/twitter_24.png

subscribe to comments RSS

There are no comments for this post

Please, feel free to post your own comment

* these are required fields