Posted By

duniyadnd on 04/21/09


Tagged

replace white space whitespace underscore


Versions (?)

Replace space with _


 / Published in: JavaScript
 

I'll never learn how to use this Markdown system. Anyway, here is the fixed code based on my comment on the following page:

http://snipplr.com/view/14206/replace-spaces-with-underscores/

I'm sorry, I don't mean to hijack the code. :(

  1. var str = "This string has too many spaces.";
  2. var result = str.replace(/(\s| |&\#160;)+/gi, "_");
  3. document.write(result);

Report this snippet  

You need to login to post a comment.