jQuery Replace craziness

B3y steven 8/10/2009 5:33:00 PM

 

I spent way too much time figuring this out.

var originalString = “Batman And Robin”;

var replacedSpaces = originalString.replace(‘ ‘, ‘_’);

This doesn’t work, it only replaces the first instace of the match, so replacedSpaces == “Batman_And Robin”.

var replacedSpaces = originalString.replace(/ /g, ‘_’);

This does work, and now replacedSpaces == “Batman_And_Robin”.

 

Tags: ,

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered By BlogEngine Enhanced with Snapshots

About the author

Steven Hildreth Steven Hildreth
Proof that anyone can setup a blog.

E-mail me LinkedIn Profile

Send mail Sign in

Recent posts