26 maj 2010

Zamiana znaków za pomocą replace - różne sposoby

JavaScript

var cat ='3,4,6,9';
alert(cat.replace(RegExp(",","g"), '_'));
alert(cat.replace(",",'_','g'));
alert(cat.replace(/,/g, '_'));

W IE7(wykonano test), działa troche inaczej niż w FF. Drugie alert zwraca inny wynik.

---------------------------
Windows Internet Explorer
---------------------------
3_4_6_9
---------------------------
OK
---------------------------

---------------------------
Windows Internet Explorer
---------------------------
3_4,6,9
---------------------------
OK
---------------------------

---------------------------
Windows Internet Explorer
---------------------------
3_4_6_9
---------------------------
OK
---------------------------