Click to See Complete Forum and Search --> : indexOf()...


xataku_nakusute
08-01-2003, 01:16 AM
is it possible to use the indexOf() thingy to change any defined letter/punction into a different letter/punction??

e.g.

<htm>
<body>
Hello!
</body>
</html>

i would write a script and using the indexOf(), replace the ! with &_#_3_3_; (i used the underscores so you can actually see what i was writing and not parsed text)

(btw, sorry for posting this twice[once in the dhtml forum], i forgot where i was :p )

AdamGundry
08-01-2003, 02:28 AM
It'd be easier just to use a regular expression (through String.replace()), like this:

var htmlStr = '<html><body>Hello!</body></html>';
var htmlStr = htmlStr.replace(/!/g, "&amp;#33;");
alert(htmlStr);

Adam

xataku_nakusute
08-01-2003, 02:55 AM
can you make it effect the whole body??
(sorry im just very lazy, and sleepy at the moment and want it ez...:p )

AdamGundry
08-01-2003, 05:49 AM
I think you can do this:

var htmlStr = document.body.innerHTML;
var htmlStr = htmlStr.replace(/!/g, "&amp;#33;");
document.body.innerHTML = htmlStr;

Adam

xataku_nakusute
08-01-2003, 03:15 PM
thanx