iterating each letter in string

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

    #1

    iterating each letter in string

    I have a string. I'd like to take this string
    and make each char change until it gets to another
    char at the same position of the string.

    Example:

    Original String: " NEW YORK "
    Final String: "SAN FRANSISCO"

    I'd like each char to loop through the chars on a timer
    and show each char in the alphabet until it gets to the
    char in the same position as the beginning char
    So the first char in the original string, which is a space,
    would loop through and show all chars until it reaches "S"

    This is supposed to look like those rollover departure/arrival
    signs in an airport when the info changes.

    Anyone???

    If you can't do this, then can you fill me in on HOW to do it?
    Maybe even some pseudocode?
  • Dietmar Meier

    #2
    Re: iterating each letter in string

    Mr.Clean wrote:
    [color=blue]
    > This is supposed to look like those rollover departure/arrival
    > signs in an airport when the info changes.[/color]

    Done that before, here it is:

    function fliptext(oElem, sDest, nTime) {
    if (
    !oElem
    || "string" != typeof oElem.value
    || "string" != typeof sDest
    ) return null;
    if (!nTime || isNaN(nTime)) nTime = 100;
    if (oElem.timer) window.clearTim eout(oElem.time r);
    var sCurr = oElem.value;
    while (sCurr.length < sDest.length) sCurr += " ";
    while (sDest.length < sCurr.length) sDest += " ";
    oElem.value = sCurr;
    oElem.dest = sDest;
    oElem.timer = window.setInter val(function() {
    var c1, c2, i, sNew = "",
    sCurr = oElem.value, sDest = oElem.dest;
    for (i=0; i<sCurr.length ; i++) {
    c1 = sCurr.charCodeA t(i);
    c2 = sDest.charCodeA t(i);
    sNew += String.fromChar Code(c2 > c1? ++c1 : c2 < c1? --c1 : c1);
    }
    oElem.value = sNew;
    if (sNew == sDest) {
    window.clearTim eout(oElem.time r);
    oElem.timer = null;
    }
    }, nTime);
    }
    [...]
    fliptext(
    document.forms['foo'].elements['bar'],
    'SAN FRANCISCO',
    100
    );
    [...]

    fliptext(
    document.forms['foo'].elements['bar'],
    ' NEW YORK',
    100
    );
    [...]
    <form name="foo" [...]>
    <input name="bar" style="font-family:monospac e;border:0">
    [...]

    ciao, dhgm

    Comment

    • Mr.Clean

      #3
      Re: iterating each letter in string

      In article <36h80bF511mksU 1@individual.ne t>, usereplytoinste ad@innoline-
      systemtechnik.d e says...[color=blue]
      > Mr.Clean wrote:
      >[color=green]
      > > This is supposed to look like those rollover departure/arrival
      > > signs in an airport when the info changes.[/color]
      >
      > Done that before, here it is:[/color]

      How can I limit the chars that it flips through and set the length
      of the result/destination string?

      "ABCDEFGHIJKLMN OPQRSTUVWXYZ .-"

      Comment

      • Dietmar Meier

        #4
        Re: iterating each letter in string

        Mr.Clean wrote:
        [color=blue]
        > How can I limit the chars that it flips through[/color]

        Some changes, quick hacked and mostly untested:

        function fliptext(oElem, sDest, nTime) {
        var i, c, s, sDispChars = " ABCDEFGHIJKLMNO PQRSTUVWXYZ-.";
        if (!oElem || "string" != typeof oElem.value) return null;
        if (oElem.timer) window.clearTim eout(oElem.time r);
        var sCurr = oElem.value.toU pperCase();
        sDest = sDest.toUpperCa se();
        while (sCurr.length < sDest.length) sCurr += " ";
        while (sDest.length < sCurr.length) sDest += " ";
        sCurr = sCurr.toUpperCa se();
        for (i=0, s=""; i<sCurr.length ; i++)
        s += sDispChars.inde xOf(c = sCurr.charAt(i) ) > -1? c : " ";
        oElem.value = s.toUpperCase() ;
        for (i=0, s=""; i<sDest.length ; i++)
        s += sDispChars.inde xOf(c = sDest.charAt(i) ) > -1? c : " ";
        oElem.dest = s.toUpperCase() ;
        oElem.timer = window.setInter val(function() {
        var c1, c2, i, sNew = "",
        sCurr = oElem.value, sDest = oElem.dest;
        for (i=0; i<sCurr.length ; i++) {
        c1 = sDispChars.inde xOf(sCurr.charA t(i));
        c2 = sDispChars.inde xOf(sDest.charA t(i));
        sNew += sDispChars.char At(c2 > c1? ++c1 : c2 < c1? --c1 : c1);
        }
        oElem.value = sNew;
        if (sNew == sDest) {
        window.clearTim eout(oElem.time r);
        oElem.timer = null;
        }
        }, nTime);
        }
        [color=blue]
        > and set the length of the result/destination string?[/color]

        The lenght used is the maximum of the lengths of the two strings
        sDest and sCurr. To get an output with more characters, simply
        add some spaces to the second argument, sDest.

        ciao, dhgm

        Comment

        • RobG

          #5
          Re: iterating each letter in string

          Dietmar Meier wrote:[color=blue]
          > Mr.Clean wrote:
          >[color=green]
          >> This is supposed to look like those rollover departure/arrival
          >> signs in an airport when the info changes.[/color]
          >
          > Done that before, here it is:[/color]
          [...]

          Hey, liked that. Here's a twist, uses an array to constrain the
          letters used.

          Have fun

          --
          Rob

          <html><head><ti tle>Tumbler</title>
          <style type="text/css">
          ..let {
          width: 2em; height: 2em; text-align: center; color: black;
          background-color: #ddddee; border: 1px solid red;
          display: block; position: absolute; top: 0px; line-height: 2;
          font-weight: bold; font-family: sans-serif;}
          </style>
          <script type="text/javascript">

          var letters = [
          'A','B','C','D' ,'E','F','G','H ','I','J','K',' L','M','N',
          'O','P','Q','R' ,'S','T','U','V ','W','X','Y',' Z',' ','*',
          'A','B','C','D' ,'E','F','G','H ','I','J','K',' L','M','N',
          'O','P','Q','R' ,'S','T','U','V ','W','X','Y',' Z',' ','*'];

          function tumbleWord(w,d, z,lag) {
          var k = 0,
          m = 0,
          wd = '',
          oneDiff = false;
          while (document.getEl ementById(d + k)) {k++}
          while (wd.length < k) {
          (w.charAt(m))? wd += w.charAt(m) : wd += ' ';
          m++;
          }
          z.timer = window.setInter val(function() {
          for (var i=0; i<k; i++) {
          var oSlot = document.getEle mentById(d + i).firstChild;
          var oLetter = oSlot.data;
          if (oLetter != wd.charAt(i)) {
          oSlot.data = nextLetter(oLet ter);
          oneDiff = true;
          }
          }
          if (oneDiff) {
          oneDiff = false;
          } else {
          window.clearTim eout(z.timer);
          z.timer = null;
          }
          }, lag);
          }

          function nextLetter(a) {
          var j = 0;
          while (a != letters[j]) {j++}
          return letters[j+1];
          }

          </script>
          </head>
          <body>
          <form action="">
          <select id="choices" onchange="
          tumbleWord(this[selectedIndex].value,'in',thi s,'50');
          ">
          <option value="" selected>Select a destination</option>
          <option value=" NEW YORK">New York</option>
          <option value="SAN FRANCISCO">San Francisco</option>
          <option value=" SYDNEY">Sydney</option>
          <option value=" AUSCION">Auscio n</option>
          <option value=" NUUK">Nuuk</option>
          <option value=" REYKJAVIK">Reyk javik</option>
          </select>
          <input type="reset">
          </form>
          <br> <br>
          <div style="position : relative" id="tt">
          <div style="left: 2em" class="let" id="in0"> </div>
          <div style="left: 4em" class="let" id="in1"> </div>
          <div style="left: 6em" class="let" id="in2"> </div>
          <div style="left: 8em" class="let" id="in3"> </div>
          <div style="left: 10em" class="let" id="in4"> </div>
          <div style="left: 12em" class="let" id="in5"> </div>
          <div style="left: 14em" class="let" id="in6"> </div>
          <div style="left: 16em" class="let" id="in7"> </div>
          <div style="left: 18em" class="let" id="in8"> </div>
          <div style="left: 20em" class="let" id="in9"> </div>
          <div style="left: 22em" class="let" id="in10"> </div>
          <div style="left: 24em" class="let" id="in11"> </div>
          <div style="left: 26em" class="let" id="in12"> </div>
          </div>
          </body>
          </html>

          Comment

          • Mr.Clean

            #6
            Re: iterating each letter in string

            In article <4203a216$0$214 30$5a62ac22@per-qv1-newsreader-
            01.iinet.net.au >, rgqld@iinet.net .auau says...[color=blue]
            > Dietmar Meier wrote:[color=green]
            > > Mr.Clean wrote:
            > >[color=darkred]
            > >> This is supposed to look like those rollover departure/arrival
            > >> signs in an airport when the info changes.[/color]
            > >
            > > Done that before, here it is:[/color]
            > [...]
            >
            > Hey, liked that. Here's a twist, uses an array to constrain the
            > letters used.[/color]

            I get an object required error on this line:

            var oLetter = oSlot.data;

            Comment

            • RobG

              #7
              Re: iterating each letter in string

              Mr.Clean wrote:
              [...][color=blue]
              >
              > I get an object required error on this line:
              >
              > var oLetter = oSlot.data;[/color]

              Yeah, sorry, didn't test in IE... done that now though.

              Replace the above line with:

              var t = document.getEle mentById(d + i);
              if (!t.firstChild) {
              t.appendChild(d ocument.createT extNode(' '));
              }

              If the only character in the DIV is a space, IE removes the space
              and doesn't create a text node, so the DIV has no children and
              the script goes belly up. The above line adds tolerance so don't
              need any characters in the output divs to start with.

              However, it is still intolerant of characters other than those in
              the array, so be careful. If required, add a function before the
              timer is called that checks each character in the new destination
              is in the letters array. If not, replace it with an "*" or some
              other character that is in the array.

              Also need to add a line to cancel the timer if already running
              just after function declaration:

              function tumbleWord(w,d, z,lag) {
              if (z.timer) window.clearTim eout(z.timer);

              You may want to add support for pre-IE 6 browsers with an
              alternative to document.getEle mentById(). Have a look at the
              dynWrite options on this groups FAQ at:

              <URL:http://www.jibbering.c om/faq>

              I don't have an IE before 6, so can't test in that realm.

              Here's the fixed tumbleWord():

              function tumbleWord(w,d, z,lag) {
              if (z.timer) window.clearTim eout(z.timer);
              var k = 0,
              m = 0,
              wd = '',
              oneDiff = false;
              while (document.getEl ementById(d + k)) {k++}
              while (wd.length < k) {
              (w.charAt(m))? wd += w.charAt(m) : wd += ' ';
              m++;
              }
              z.timer = window.setInter val(function() {
              for (var i=0; i<k; i++) {
              var t = document.getEle mentById(d + i);
              if (!t.firstChild) {
              t.appendChild(d ocument.createT extNode(' '));
              }
              var oSlot = document.getEle mentById(d + i).firstChild;
              var oLetter = oSlot.data;
              if (oLetter != wd.charAt(i)) {
              oSlot.data = nextLetter(oLet ter);
              oneDiff = true;
              }
              }
              if (oneDiff) {
              oneDiff = false;
              } else {
              window.clearTim eout(z.timer);
              z.timer = null;
              }
              }, lag);
              }

              --
              Rob

              Comment

              • Mr.Clean

                #8
                Re: iterating each letter in string

                In article <4203acb9$0$214 29$5a62ac22@per-qv1-newsreader-
                01.iinet.net.au >, rgqld@iinet.net .auau says...[color=blue]
                > Mr.Clean wrote:
                > [...][color=green]
                > >
                > > I get an object required error on this line:
                > >
                > > var oLetter = oSlot.data;[/color]
                >
                > Yeah, sorry, didn't test in IE... done that now though.
                >[/color]

                Well, DUH...;-)

                Anyway, why do you have 2 sets of letters in the array and
                how can I add other chars to the array?

                I tried adding chars but they did not show up.

                Comment

                • Dietmar Meier

                  #9
                  Re: iterating each letter in string

                  Dietmar Meier wrote:
                  [color=blue]
                  > sNew += sDispChars.char At(c2 > c1? ++c1 : c2 < c1? --c1 : c1);[/color]

                  To make it rotate (I was told that displays at airports do not
                  roll backwards):

                  sNew += sDispChars.char At(c2 == c1? c1 : ++c1 % sDispChars.leng th);

                  ciao, dhgm

                  Comment

                  • Dr John Stockton

                    #10
                    Re: iterating each letter in string

                    JRS: In article <MPG.1c6ca499d9 28d1f8989680@ne ws-server.austin.r r.com>,
                    dated Fri, 4 Feb 2005 03:14:28, seen in news:comp.lang. javascript, Mr.
                    Clean <mrclean@pandg. com> posted :[color=blue]
                    >I have a string. I'd like to take this string
                    >and make each char change until it gets to another
                    >char at the same position of the string.
                    >
                    >Example:
                    >
                    >Original String: " NEW YORK "
                    >Final String: "SAN FRANSISCO"
                    >
                    >I'd like each char to loop through the chars on a timer
                    >and show each char in the alphabet until it gets to the
                    >char in the same position as the beginning char
                    >So the first char in the original string, which is a space,
                    >would loop through and show all chars until it reaches "S"
                    >
                    >This is supposed to look like those rollover departure/arrival
                    >signs in an airport when the info changes.
                    >
                    >Anyone???
                    >
                    >If you can't do this, then can you fill me in on HOW to do it?
                    >Maybe even some pseudocode?[/color]

                    Here is working general code to do it at full speed :-

                    var S1, S2 : string ; J, P : byte ;
                    const chars : string = ' ABCDEFGHIJKLMNO PQRSTUVWXYZ' ;
                    BEGIN ;
                    S1 := ' NEW YORK ' ;
                    S2 := 'SAN FRANCISCO' ;
                    for J := 1 to length(S1) do begin
                    while S1[J]<>S2[J] do begin
                    P := Pos(S1[J], chars) ;
                    if P=Length(chars) then P := 1 else Inc(P) ; // P%=L
                    S1[J] := chars[P] ; // .. ++P
                    Writeln(S1) ; // DynWrite
                    end ;
                    end ;
                    END.

                    You'll have to make it javascript, and turn it round to fit with the
                    usual sort of setTimeout loop; at each step, do the four central lines.

                    NEVER fly to/from an airport that spells SF like your example.

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                    Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
                    PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
                    Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

                    Comment

                    • Mr.Clean

                      #11
                      Re: iterating each letter in string

                      <SNIP>[color=blue]
                      > You'll have to make it javascript, and turn it round to fit with the
                      > usual sort of setTimeout loop; at each step, do the four central lines.
                      >[/color]
                      I already had Delphi code doing it, just didn't know how in javascript.

                      [color=blue]
                      > NEVER fly to/from an airport that spells SF like your example.
                      >[/color]

                      My Bad...

                      E.

                      Comment

                      • RobB

                        #12
                        Re: iterating each letter in string

                        Mr.Clean wrote:[color=blue]
                        > <SNIP>[color=green]
                        > > You'll have to make it javascript, and turn it round to fit with[/color][/color]
                        the[color=blue][color=green]
                        > > usual sort of setTimeout loop; at each step, do the four central[/color][/color]
                        lines.[color=blue][color=green]
                        > >[/color]
                        > I already had Delphi code doing it, just didn't know how in[/color]
                        javascript.[color=blue]
                        >
                        >[color=green]
                        > > NEVER fly to/from an airport that spells SF like your example.
                        > >[/color]
                        >
                        > My Bad...
                        >
                        > E.[/color]
                        [color=blue]
                        >From the outskirts of San Fransisco \:=O comes yet another. Watch for[/color]
                        google-wrap-crap.

                        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                        "http://www.w3.org/TR/html4/strict.dtd">
                        <html>
                        <head>
                        <title>|-| flipboard |-|</title>
                        <style type="text/css">

                        body {
                        background: #000;
                        }

                        #flipboard {
                        width: 544px;
                        height: 32px;
                        margin: 120px auto;
                        border: 6px #fff outset;
                        }
                        ..slot {
                        float: left;
                        width: 32px;
                        height: 32px;
                        font: 24px "arial black";
                        text-align: center;
                        background:
                        url(http://www.grsites.com/textures/metal_b/metal_b002.jpg) silver;
                        }
                        select {
                        font: normal 10px arial, sans-serif;
                        color: #fff;
                        background: #888;
                        }

                        </style>
                        <script type="text/javascript">

                        String.prototyp e.nextLetter = function()
                        {
                        var ab = 'abcdefghijklmn opqrstuvwxyza',
                        idx, c, s = '';
                        for (var i = 0, l = this.length; i < l; ++i)
                        {
                        c = this.charAt(i);
                        s +=
                        ((idx = ab.indexOf(c)) != -1) ?
                        ab.charAt(idx + 1) :
                        ((idx = ab.indexOf(c.to LowerCase())) != -1) ?
                        ab.charAt(idx + 1).toUpperCase( ) : c;
                        }
                        return s;
                        }

                        function FlipBoard(board _id, delay)
                        {
                        var obj = this;
                        var x = 0, slot;
                        this.board = document.getEle mentById(board_ id);
                        this.slots = this.board.getE lementsByTagNam e('div');
                        this.delay = delay;
                        this.spos = 0;
                        this.cpos = 0;
                        this.running = false;
                        while (slot = this.slots.item (x++))
                        while (!slot.hasChild Nodes())
                        slot.appendChil d(document.crea teTextNode('\u0 020'));

                        this.flip = function(new_st r)
                        {
                        if (this.running)
                        return;
                        this.running = true;
                        this.board.styl e.borderStyle = 'ridge';
                        this.spos = 0;
                        this.cpos = 0;
                        this.start =
                        Math.ceil(this. slots.length * .5) -
                        Math.ceil(new_s tr.length * .5);
                        this.timer =
                        setInterval(
                        function()
                        {
                        var c = obj.slots.item( obj.spos);
                        if (c)
                        {
                        var nc = new_str.charAt( obj.cpos);
                        if (obj.spos < obj.start)
                        {
                        c.firstChild.no deValue = ' ';
                        obj.spos++;
                        return;
                        }
                        if (nc == '' || nc == ' ')
                        {
                        c.firstChild.no deValue = ' ';
                        obj.spos++;
                        obj.cpos++;
                        return;
                        }
                        var l = c.firstChild.no deValue;
                        var isLow = (nc == nc.toLowerCase( ));
                        if (l == ' ')
                        {
                        var ll = 'A';
                        c.firstChild.no deValue =
                        ll[isLow ? 'toLowerCase' : 'toUpperCase']();
                        return;
                        }
                        if (l != nc)
                        {
                        c.firstChild.no deValue =
                        l[isLow ? 'toLowerCase' : 'toUpperCase']().nextLetter() ;
                        return;
                        }
                        else
                        {
                        obj.spos++;
                        obj.cpos++;
                        return;
                        }
                        }
                        else
                        {
                        clearInterval(o bj.timer);
                        obj.board.style .borderStyle = 'outset';
                        obj.running = false;
                        }
                        }, this.delay);
                        }
                        }

                        onload = function()
                        {
                        x = new FlipBoard('flip board', 40)
                        }

                        </script>
                        </head>
                        <body>
                        <select size="6"
                        onchange="x.fli p(this.value);t his.selectedInd ex=-1">
                        <option value="SAN FRANCISCO">SAN FRANCISCO</option>
                        <option value="NEW ORLEANS">NEW ORLEANS</option>
                        <option value="MINNEAPO LIS">MINNEAPOLI S</option>
                        <option value="Honolulu ">Honolulu</option>
                        <option value="KUALA LUMPUR">KUALA LUMPUR</option>
                        <option value="West Palm Beach">West Palm Beach</option>
                        </select>
                        </form>
                        <div id="flipboard" >
                        <div class="slot"></div>
                        <div class="slot"></div>
                        <div class="slot"></div>
                        <div class="slot"></div>
                        <div class="slot">B</div>
                        <div class="slot">A</div>
                        <div class="slot">L</div>
                        <div class="slot">T</div>
                        <div class="slot">I</div>
                        <div class="slot">M</div>
                        <div class="slot">O</div>
                        <div class="slot">R</div>
                        <div class="slot">E</div>
                        <div class="slot"></div>
                        <div class="slot"></div>
                        <div class="slot"></div>
                        <div class="slot"></div>
                        </div>
                        </body>
                        </html>

                        Comment

                        • RobG

                          #13
                          Re: iterating each letter in string

                          Mr.Clean wrote:[color=blue]
                          > In article <4203acb9$0$214 29$5a62ac22@per-qv1-newsreader-
                          > 01.iinet.net.au >, rgqld@iinet.net .auau says...
                          >[color=green]
                          >>Mr.Clean wrote:
                          >>[...]
                          >>[color=darkred]
                          >>>I get an object required error on this line:
                          >>>
                          >>>var oLetter = oSlot.data;[/color]
                          >>
                          >> Yeah, sorry, didn't test in IE... done that now though.
                          >>[/color]
                          >
                          >
                          > Well, DUH...;-)
                          >
                          > Anyway, why do you have 2 sets of letters in the array and
                          > how can I add other chars to the array?
                          >
                          > I tried adding chars but they did not show up.
                          >[/color]

                          The nextLetter function looks for the first instance of a letter,
                          then gets the next one. I could have:

                          - worked out which way to tumble, but that requires 2 lookups per
                          letter change
                          - skipped back to the beginning of the array if the end is
                          reached (perhaps a better solution)
                          - made two sets of the same characters, so wherever the array
                          found the current character, the destination character was
                          always further along

                          Here is a new nextLetter that lets you have just one set of
                          letters:

                          function nextLetter(a) {
                          var j = 0;
                          while (a != letters[j]) {j++}
                          return (j == letters.length-1)? letters[0] : letters[j+1];
                          }

                          If the character matches the last in the array, it skips to the
                          first element.

                          So now your array can be:

                          var letters = [
                          '*','A','B','C' ,'D','E','F','G ','H','I','J',' K','L','M',
                          'N','O','P','Q' ,'R','S','T','U ','V','W','X',' Y','Z',' '
                          ];

                          There is a reason why the asterisk is first...

                          The following checks that the letters in the destination are in
                          the array. If they aren't, it replaces the letter with the first
                          in the array.

                          function checkLetter(b) {
                          for (var i=0, len=letters.len gth; i<len; i++) {
                          if (letters[i] == b) return b;
                          }
                          return letters[0];
                          }

                          And change this line:

                          (w.charAt(m))? wd += w.charAt(m) : wd += ' ';

                          to this:

                          (w.charAt(m))? wd += checkLetter(w.c harAt(m)) : wd += ' ';

                          Test in IE and Firefox, full script below.

                          --
                          Rob

                          <script type="text/javascript">

                          var letters = [
                          '*','A','B','C' ,'D','E','F','G ','H','I','J',' K','L','M',
                          'N','O','P','Q' ,'R','S','T','U ','V','W','X',' Y','Z',' '
                          ];

                          function tumbleWord(w,d, z,lag) {
                          if (z.timer) window.clearTim eout(z.timer);
                          var k = 0,
                          m = 0,
                          wd = '',
                          oneDiff = false;
                          while (document.getEl ementById(d + k)) {k++}
                          while (wd.length < k) {
                          (w.charAt(m))? wd += checkLetter(w.c harAt(m)) : wd += ' ';
                          m++;
                          }
                          z.timer = window.setInter val(function() {
                          for (var i=0; i<k; i++) {
                          var t = document.getEle mentById(d + i);
                          if (!t.firstChild)
                          t.appendChild(d ocument.createT extNode(' '));
                          oSlot = t.firstChild;
                          var oLetter = oSlot.data;
                          if (oLetter != wd.charAt(i)) {
                          oSlot.data = nextLetter(oLet ter);
                          oneDiff = true;
                          }
                          }
                          if (oneDiff) {
                          oneDiff = false;
                          } else {
                          window.clearTim eout(z.timer);
                          z.timer = null;
                          }
                          }, lag);
                          }

                          function nextLetter(a) {
                          var j = 0;
                          while (a != letters[j]) {j++}
                          return (j == letters.length-1)? letters[0] : letters[j+1];
                          }

                          function checkLetter(b) {
                          for (var i=0, len=letters.len gth; i<len; i++) {
                          if (letters[i] == b) return b;
                          }
                          return letters[0];
                          }
                          </script>

                          Comment

                          • Dr John Stockton

                            #14
                            Re: iterating each letter in string

                            JRS: In article <1107546516.6b2 299708d66ee7bc8 352b59c1b8e037@ teranews>,
                            dated Fri, 4 Feb 2005 13:48:36, seen in news:comp.lang. javascript, Mr.
                            Clean <mrclean@p&g.co m> posted :[color=blue]
                            ><SNIP>[color=green]
                            >> You'll have to make it javascript, and turn it round to fit with the
                            >> usual sort of setTimeout loop; at each step, do the four central lines.
                            >>[/color]
                            >I already had Delphi code doing it, just didn't know how in javascript.[/color]

                            That was not written in Delphi ...

                            --
                            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
                            <URL:http://www.merlyn.demo n.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
                            <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.

                            Comment

                            • Mr.Clean

                              #15
                              Re: iterating each letter in string

                              In article <ISJeIsCKTLBCFw q1@merlyn.demon .co.uk>,
                              spam@merlyn.dem on.co.uk says...[color=blue]
                              > JRS: In article <1107546516.6b2 299708d66ee7bc8 352b59c1b8e037@ teranews>,
                              > dated Fri, 4 Feb 2005 13:48:36, seen in news:comp.lang. javascript, Mr.
                              > Clean <mrclean@p&g.co m> posted :[color=green]
                              > ><SNIP>[color=darkred]
                              > >> You'll have to make it javascript, and turn it round to fit with the
                              > >> usual sort of setTimeout loop; at each step, do the four central lines.
                              > >>[/color]
                              > >I already had Delphi code doing it, just didn't know how in javascript.[/color]
                              >
                              > That was not written in Delphi ...
                              >
                              >[/color]
                              Close enough...<bg>

                              Comment

                              Working...