Replace method of String object doesn't work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas

    Replace method of String object doesn't work

    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
  • Grant Wagner

    #2
    Re: Replace method of String object doesn't work

    Thomas wrote:
    [color=blue]
    > 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[/color]

    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:
    Gain technical skills through documentation and training, earn certifications and connect with the community

    /> 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 <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Gain technical skills through documentation and training, earn certifications and connect with the community


    * 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-deve...upgrade_2.html


    Comment

    Working...