Posted By

duniyadnd on 04/21/09


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:

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.