PDA

View Full Version : string function replace help



gingerj
04-04-2006, 09:19 AM
Hi I'm trying to replace commas in a string with spaces, it works for the first instance of a commas. but I dont know how to remove the rest:



var aString = "Humpty,Dumpty,sat,on,a,wall";
document.write(aString.replace(","," "));

jscheuer1
04-04-2006, 09:32 AM
var aString = "Humpty,Dumpty,sat,on,a,wall";
document.write(aString.replace(/,/g, ' '));

The g means 'global'

gingerj
04-04-2006, 09:41 AM
Thank you very much