Replace space with _


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

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. :(


Copy this code and paste it in your HTML
  1. var str = "This string has too many spaces.";
  2. var result = str.replace(/(\s| |&\#160;)+/gi, "_");
  3. document.write(result);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.