En javascript la fonction Replace n'existe pas, voici donc une fonction qui le fait :
function replace(string,text,by) { // Replaces text with by in string var strLength = string.length, txtLength = text.length; if ((strLength == 0) || (txtLength == 0)) return string; var i = string.indexOf(text); if ((!i) && (text != string.substring(0,txtLength))) return string; if (i == -1) return string; var newstr = string.substring(0,i) + by; if (i+txtLength < strLength) newstr += replace(string.substring(i+txtLength,strLength),text,by); return newstr; }
Discussion
Je vais peut-être dire une bêtise mais ce n’est pas ceci :
string.replace(); ?
http://www.toutjavascript.com/reference/reference.php?iref=43
Si tout a fait, mais c’est la version pour ceux qui ne comprenne rien au expression réguliere ;)