Replace method of String object doesn't work

T

Thomas

It looks like the String.replace doesn't work in IE6.1. Anyone else
has the same problem. I am using newest service package of IE and
Win2K.

Thanks
 
G

Grant Wagner

Thomas said:
It looks like the String.replace doesn't work in IE6.1. Anyone else
has the same problem. I am using newest service package of IE and
Win2K.

Thanks

There are a number of issues going on here.

One, there is no such thing as IE 6.1, the latest version of IE is 6.0
Service Pack 1.

Two, just because you are running IE 6.0SP1 does not guarantee that you
are running JScript 5.6, the way to verify this is to go to:

Start -> Run -> type "cmd", hit Enter
type "cscript", hit Enter
You should see something similar to "Microsoft (R) Windows Script Host
Version 5.6", the number you see there is the version of JScript you are
using. If it's anything other then 5.6, check <url:
http://msdn.microsoft.com/library/en-us/script56/html/js56jsoriversioninformation.asp
/> to see if String.replace() is a supported method for your version of
JScript (hint: replace() has been a method of the String object since
JScript 1.0).

Three, alert("My String".replace(/String$/, "New String")); works just
fine.

Four, note that String objects are immutable, that is, you don't modify
the original String when you call replace(), but instead a new String
object is returned that contains the replaced String.

var s = "My String";
s.replace(/String$/, "New String");
alert(s);
// alerts "My String"

var s = "My String";
s = s.replace(/String$/, "New String");
alert(s);
// alerts "My New String"

In the future, instead of simply stating that some method doesn't work,
perhaps you could include the simplest example of your code that
exhibits the incorrect behaviour. Often the very act of simplifying your
code to demostrate the problem reveals the cause of the problem.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top