charcodeat in IE

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

    charcodeat in IE

    msdn docs say the String.charCode At method is supported by IE 5.5 and above.
    I'm just curious that what do people use before IE 5.5 was released?
    charCodeAt seems to be such an important method.


  • VK

    #2
    Re: charcodeat in IE

    myString.charAt (x).escape()
    Gives you %FF formated ASCII code
    Supported since LiteScript (> JavaScript 1.0)
    Fails on Unicode of course, but there was not any that time :-)




    Comment

    • Bern

      #3
      Re: charcodeat in IE

      i thought the "escape" function should be used like this:

      escape ("xxx...$%$" )

      anyway is there an alternative to charCodeAt that still works *now*?

      the "escape" fucntion does not format alphanumeric chars.

      "VK" <schools_ring@y ahoo.com> wrote in message
      news:416d1861$0 $168$9b622d9e@n ews.freenet.de. ..[color=blue]
      > myString.charAt (x).escape()
      > Gives you %FF formated ASCII code
      > Supported since LiteScript (> JavaScript 1.0)
      > Fails on Unicode of course, but there was not any that time :-)
      >
      >
      >
      >[/color]


      Comment

      • VK

        #4
        Re: charcodeat in IE

        oops... sorry, I was thinking of the second part of the table (>128)... this
        is what I had to deal with.

        For the chars in the dead-zone (## 33 - 122 with breaks for some "escapable"
        chars) we used preset arrays to compare with.

        if (escape(c) == c) { // doesn't escape, x!o! :-)
        // then iterate throu the array
        //
        // yes, old times are not always good :-)
        //
        // what is your biz, any way?
        // maybe there is some better approach to your needs?
        }


        Comment

        • Bern

          #5
          Re: charcodeat in IE

          i got your idea.

          var charcodes = new Array();
          charcodes ['A'] = 65;
          charcodes ['B'] = 66;
          .....

          anyway, i am doing a md5 calculation script.
          Can imagine how huge an old md5 script will be...

          "VK" <schools_ring@y ahoo.com> wrote in message
          news:416d40f9$0 $28179$9b622d9e @news.freenet.d e...[color=blue]
          > oops... sorry, I was thinking of the second part of the table (>128)...[/color]
          this[color=blue]
          > is what I had to deal with.
          >
          > For the chars in the dead-zone (## 33 - 122 with breaks for some[/color]
          "escapable"[color=blue]
          > chars) we used preset arrays to compare with.
          >
          > if (escape(c) == c) { // doesn't escape, x!o! :-)
          > // then iterate throu the array
          > //
          > // yes, old times are not always good :-)
          > //
          > // what is your biz, any way?
          > // maybe there is some better approach to your needs?
          > }
          >
          >[/color]


          Comment

          • VK

            #6
            Re: charcodeat in IE

            [color=blue]
            > var charcodes = new Array();
            > charcodes ['A'] = 65;
            > charcodes ['B'] = 66;
            > ....[/color]

            I'm not sure you can init Array with char index values instead of integers,
            but I may be just missing the train of progress :-)

            In our case it was:

            var charcodes = new Array();
            ....
            charcodes[65] = 'A';
            charcodes[66] = 'B'
            ....
            // and then:
            if (escape(c) == c) {
            for (i = 33; i <=122; i++) {
            if (c == charcodes[i]) {
            // i contains the charcode
            }
            }
            }


            Comment

            • Randy Webb

              #7
              Re: charcodeat in IE

              VK wrote:
              [color=blue][color=green]
              >>var charcodes = new Array();
              >>charcodes ['A'] = 65;
              >>charcodes ['B'] = 66;
              >>....[/color]
              >
              >
              > I'm not sure you can init Array with char index values instead of integers,
              > but I may be just missing the train of progress :-)[/color]

              Yes, you can add them that way, but the length of the array stays 0.


              --
              Randy
              comp.lang.javas cript FAQ - http://jibbering.com/faq

              Comment

              • Lasse Reichstein Nielsen

                #8
                Re: charcodeat in IE

                "VK" <schools_ring@y ahoo.com> writes:
                [color=blue][color=green]
                >> var charcodes = new Array();
                >> charcodes ['A'] = 65;
                >> charcodes ['B'] = 66;
                >> ....[/color]
                >
                > I'm not sure you can init Array with char index values instead of integers,
                > but I may be just missing the train of progress :-)[/color]

                You can. It doesn't need to be an array, though. A simple Object would
                suffice, since arrays are just special objects that have extra
                functionality related to properties that have integers as names.
                Also, in Javascript 'A' is not a "char", but a string.

                /L
                --
                Lasse Reichstein Nielsen - lrn@hotpop.com
                DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                • Dr John Stockton

                  #9
                  Re: charcodeat in IE

                  JRS: In article <416cfb34$1@new s.starhub.net.s g>, dated Wed, 13 Oct
                  2004 17:55:34, seen in news:comp.lang. javascript, Bern <x@x.com> posted
                  :[color=blue]
                  >msdn docs say the String.charCode At method is supported by IE 5.5 and above.[/color]

                  I doubt whether they say that it is not available before IE5.5.
                  [color=blue]
                  >I'm just curious that what do people use before IE 5.5 was released?
                  >charCodeAt seems to be such an important method.[/color]

                  It is in MS IE 4.0 as delivered with initial Win98.

                  Small Flanagan says it's ECMA-262 & JS 1.2.

                  It's in ECMA 15.5.4.5.

                  --
                  © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                  <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                  <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                  <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                  Comment

                  • Grant Wagner

                    #10
                    Re: charcodeat in IE

                    If you're going to do it that way, there is no need to define this stuff
                    manually:

                    var charcodes = new Object(); // or {}
                    // note object, not Array, you are going to be
                    // creating properties of an object, not members
                    // of an Array
                    var i = 91;
                    while (i-- > 65) { // Z to A
                    charcodes[String.fromChar Code(i)] = i;
                    }
                    i = 123;
                    while (i-- > 97) { // z to a
                    charcodes[String.fromChar Code(i)] = i;
                    }
                    // alternative to have all character codes from 255 to 0:
                    // var i = 256;
                    // while (i-- > 0) {
                    // charcodes[String.fromChar Code(i)] = i;
                    // }

                    for (var eachchar in charcodes) {
                    document.write( eachchar + ' = ' + charcodes[eachchar] + '<br>');
                    }

                    Since String#fromChar Code() has been available since Internet Explorer 4
                    (<url:
                    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

                    />), this should be fairly safe.

                    However, if you're only testing one or two characters one or two times, it
                    may be more efficient to just do:

                    if (myCharacter == String.fromChar Code(##)) { ...

                    Bern wrote:
                    [color=blue]
                    > i got your idea.
                    >
                    > var charcodes = new Array();
                    > charcodes ['A'] = 65;
                    > charcodes ['B'] = 66;
                    > ....
                    >
                    > anyway, i am doing a md5 calculation script.
                    > Can imagine how huge an old md5 script will be...
                    >
                    > "VK" <schools_ring@y ahoo.com> wrote in message
                    > news:416d40f9$0 $28179$9b622d9e @news.freenet.d e...[color=green]
                    > > oops... sorry, I was thinking of the second part of the table (>128)...[/color]
                    > this[color=green]
                    > > is what I had to deal with.
                    > >
                    > > For the chars in the dead-zone (## 33 - 122 with breaks for some[/color]
                    > "escapable"[color=green]
                    > > chars) we used preset arrays to compare with.
                    > >
                    > > if (escape(c) == c) { // doesn't escape, x!o! :-)
                    > > // then iterate throu the array
                    > > //
                    > > // yes, old times are not always good :-)
                    > > //
                    > > // what is your biz, any way?
                    > > // maybe there is some better approach to your needs?
                    > > }[/color][/color]

                    --
                    Grant Wagner <gwagner@agrico reunited.com>
                    comp.lang.javas cript FAQ - http://jibbering.com/faq

                    Comment

                    Working...