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


xataku_nakusute
08-01-2003, 01:12 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)

gil davis
08-01-2003, 07:23 AM
Not directly. You would have to split the string using the results of indexOf() and then concatenate the strings with the new character.

var test = "123!456";
var lt = test.substr(0, test.indexOf("!"));
var rt = test.substr(test.indexOf("!") + 1);
test = lt + "&amp;#33;" + rt;

AdamGundry
08-01-2003, 11:02 AM
Cross-posted and answered in the Javascript forum (http://forums.webdeveloper.com/showthread.php?s=&threadid=14429).