Reading an array of numbers

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

    Reading an array of numbers

    I want to read this array backwards.

    Its not my site so I cant find the arrays name

    instead of:
    1319710,847,162 0107 -1,-1,-1

    i want
    line1 = 1319710,847,162 0107
    line2 = -1,-1,-1

    PLZ HELP!
  • Bart Van der Donck

    #2
    Re: Reading an array of numbers

    The Ax wrote:
    I want to read this array backwards.

    Its not my site so I cant find the arrays name
    It's not possible by default to read data from another domain:


    If you have the possibility to install Perl scripts, you might be
    interested in a cross-domain AJAX call:
    AJAX Cross Domain is a free library in Perl that allows to perform AJAX requests between different domains.

    instead of:
    1319710,847,162 0107 -1,-1,-1
    >
    i want
    line1 = 1319710,847,162 0107
    line2 = -1,-1,-1
    Suppose you have put the output from your link in a js variable, then
    you could do this:

    // Initial data (exact from your link)
    var data = '1319842,847,16 20107\n';
    data += '-1,-1,-1\n';
    data += '-1,-1,-1\n';
    data += '-1,-1,-1\n';
    data += '1986686,54,151 953\n';
    data += '738525,63,3700 92\n';
    data += '1344192,41,435 35\n';
    data += '1647561,47,813 44\n';
    data += '-1,-1,-1\n';
    data += '1344271,62,347 527\n';
    data += '887647,54,1514 08\n';
    data += '-1,-1,-1\n';
    data += '1551896,43,530 20\n';
    data += '1281239,44,596 64\n';
    data += '1700818,41,430 35\n';
    data += '-1,-1,-1\n';
    data += '-1,-1,-1\n';
    data += '1291525,31,157 71\n';
    data += '-1,-1,-1\n';
    data += '-1,-1,-1\n';
    data += '-1,-1,-1\n';
    data += '427209,42,4816 4\n';
    data += '-1,-1,-1\n';
    data += '-1,-1,-1\n';
    data += '-1,-1,-1\n';
    data += '-1,-1\n';
    data += '-1,-1\n';
    data += '-1,-1\n';
    data += '-1,-1';

    // Split on end-of-line
    var line = data.split('\n' );

    // Now print the ones you like (the first starts at zero)
    alert(line[0]);
    alert(line[1]);
    alert(line[14]);

    Info about the 'split()'-method:
    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


    Hope this helps,

    --
    Bart

    Comment

    • kaydub

      #3
      Re: Reading an array of numbers

      On Jul 31, 4:24 pm, The Ax <japan...@gmail .comwrote:
      I want to read this array backwards.http://hiscore.runescape.com/index_l...r=grimmstriker
      Its not my site so I cant find the arrays name
      >
      instead of:
      1319710,847,162 0107 -1,-1,-1
      >
      i want
      line1 = 1319710,847,162 0107
      line2 = -1,-1,-1
      >
      PLZ HELP!
      Whatup The Ax:

      Try something like this, just add the request to get the string from
      the url, split it into a stack and pop em off the end.

      var myString = "1319851,847,16 20107 -1,-1,-1 -1,-1,-1 -1,-1,-1
      1986710,54,1519 53 738534,63,37009 2 1344203,41,4353 5 1647581,47,8134 4
      -1,-1,-1 1344287,62,3475 27 887655,54,15140 8 -1,-1,-1 1551915,43,5302 0
      1281250,44,5966 4 1700835,41,4303 5 -1,-1,-1 -1,-1,-1 1291539,31,1577 1
      -1,-1,-1 -1,-1,-1 -1,-1,-1 427213,42,48164 -1,-1,-1 -1,-1,-1 -1,-1,-1
      -1,-1 -1,-1 -1,-1 -1,-1";
      var myArr = myString.split( ",");

      var myBackwardStrin g = "";
      while(myArr.len gth) {
      myBackwardStrin g += myArr.pop()+',' ;
      }
      document.write( myBackwardStrin g);

      Good Luck!
      Kev

      Comment

      • Evertjan.

        #4
        Re: Reading an array of numbers

        kaydub wrote on 31 jul 2008 in comp.lang.javas cript:
        On Jul 31, 4:24 pm, The Ax <japan...@gmail .comwrote:
        >I want to read this array
        >backwards.http://hiscore.runescape.com/index_l...yer=grimmstrik
        >er Its not my site so I cant find the arrays name
        >>
        >instead of:
        >1319710,847,16 20107 -1,-1,-1
        >>
        >i want
        >line1 = 1319710,847,162 0107
        >line2 = -1,-1,-1
        >>
        >PLZ HELP!
        Whatup The Ax:
        >
        Try something like this, just add the request to get the string from
        the url, split it into a stack and pop em off the end.
        >
        var myString = "1319851,847,16 20107 -1,-1,-1 -1,-1,-1 -1,-1,-1
        1986710,54,1519 53 738534,63,37009 2 1344203,41,4353 5 1647581,47,8134 4
        -1,-1,-1 1344287,62,3475 27 887655,54,15140 8 -1,-1,-1 1551915,43,5302 0
        1281250,44,5966 4 1700835,41,4303 5 -1,-1,-1 -1,-1,-1 1291539,31,1577 1
        -1,-1,-1 -1,-1,-1 -1,-1,-1 427213,42,48164 -1,-1,-1 -1,-1,-1 -1,-1,-1
        -1,-1 -1,-1 -1,-1 -1,-1";
        var myArr = myString.split( ",");
        >
        var myBackwardStrin g = "";
        while(myArr.len gth) {
        myBackwardStrin g += myArr.pop()+',' ;
        >}
        document.write( myBackwardStrin g);
        >
        KISS:

        var myString = '1319851,847,16 20107 -1,-1,-1 -1';
        var myBackwardStrin g = myString.split( ',').reverse(). join(',');
        document.write( myBackwardStrin g);




        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • SAM

          #5
          Re: Reading an array of numbers

          The Ax a écrit :
          I want to read this array backwards.

          Its not my site so I cant find the arrays name
          >
          instead of:
          1319710,847,162 0107 -1,-1,-1
          >
          i want
          line1 = 1319710,847,162 0107
          line2 = -1,-1,-1
          The source code is exactly as you want.

          Once on the page, type in addresses bar :

          javascript:docu ment.body.inner HTML="<pre>"+do cument.body.inn erHTML+"<\/pre>"

          --
          sm

          Comment

          • The Ax

            #6
            Re: Reading an array of numbers

            On Jul 31, 8:14 am, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
            wrote:
            The Ax a écrit :
            >
            I want to read this array backwards.

            Its not my site so I cant find the arrays name
            >
            instead of:
            1319710,847,162 0107 -1,-1,-1
            >
            i want
            line1 = 1319710,847,162 0107
            line2 = -1,-1,-1
            >
            The source code is exactly as you want.
            >
            Once on the page, type in addresses bar :
            >
            javascript:docu ment.body.inner HTML="<pre>"+do cument.body.inn erHTML+"<\/pre>"
            >
            --
            sm
            Maybe I was'nt quite clear enough.

            I want to download those numbers (separated by \n) into my web page
            BUT, the numbers are not always the same.

            Does that make sence?

            Thanks for the feedback

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: Reading an array of numbers

              Bart Van der Donck wrote:
              The Ax wrote:
              >instead of:
              >1319710,847,16 20107 -1,-1,-1
              >>
              >i want
              >line1 = 1319710,847,162 0107
              >line2 = -1,-1,-1
              >
              Suppose you have put the output from your link in a js variable, then
              you could do this:
              >
              // Initial data (exact from your link)
              var data = '1319842,847,16 20107\n';
              data += '-1,-1,-1\n';
              data += '-1,-1,-1\n';
              data += '-1,-1,-1\n';
              [...]
              data += '-1,-1';
              Please don't you ever suggest such junk here again. The least that can be
              done is

              var data = '1319842,847,16 20107\n'
              + '-1,-1,-1\n'
              + '-1,-1,-1\n'
              ...
              + '-1,-1';
              // Split on end-of-line
              var line = data.split('\n' );
              >
              // Now print the ones you like (the first starts at zero)
              alert(line[0]);
              alert(line[1]);
              alert(line[14]);
              That does not solve the OPs parsing problem at all. This would:

              var s = "1319710,847,16 20107 -1,-1,-1";
              var lines = s.split(/\s+/);

              lines[0]
              ...
              lines[14]
              Info about the 'split()'-method:
              http://www.w3schools.com/jsref/jsref_split.asp
              W3Schools is junk, too. Experience shows it is to be recommended against as
              a Web development reference instead.


              PointedEars
              --
              Anyone who slaps a 'this page is best viewed with Browser X' label on
              a Web page appears to be yearning for the bad old days, before the Web,
              when you had very little chance of reading a document written on another
              computer, another word processor, or another network. -- Tim Berners-Lee

              Comment

              • SAM

                #8
                Re: Reading an array of numbers

                The Ax a écrit :
                On Jul 31, 8:14 am, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
                wrote:
                >The Ax a écrit :
                >>
                >>I want to read this array backwards.
                >>http://hiscore.runescape.com/index_l...r=grimmstriker
                >>Its not my site so I cant find the arrays name
                >>instead of:
                >>1319710,847,1 620107 -1,-1,-1
                >>i want
                >>line1 = 1319710,847,162 0107
                >>line2 = -1,-1,-1
                >The source code is exactly as you want.
                >>
                >Once on the page, type in addresses bar :
                >>
                >javascript:doc ument.body.inne rHTML="<pre>"+d ocument.body.in nerHTML+"<\/pre>"
                >
                Maybe I was'nt quite clear enough.
                >
                I want to download those numbers (separated by \n) into my web page
                BUT, the numbers are not always the same.
                Yes, and ?
                The separator (\n) is always the same, no ?
                Does that make sence?
                What is the problem ?
                Thanks for the feedback
                It's OK too with
                javascript:aler t(document.body .innerHTML);
                as this is too with :
                javascript:docu ment.body.inner HTML=document.b ody.innerHTML.s plit('\n').join ('<br>');
                or this one :
                javascript:docu ment.body.inner HTML=document.b ody.innerHTML.r eplace(/\n/g,'<br>');

                In your page that could give :
                document.getEle mentById('resul ts').innerHTML= trucbidule.spli t('\n').join('< br>');
                or :
                document.getEle mentById('resul ts').innerHTML= trucbidule.repl ace(/\n/g,'<br>');

                The alone question would have to be : how to get 'trucbidule' ?
                If 'index_lite.ws' is not on same domain as your page you can't get it
                with only the JavaScript; you'll have to use server side code.

                --
                sm

                Comment

                • Bart Van der Donck

                  #9
                  Re: Reading an array of numbers

                  Thomas 'PointedEars' Lahn wrote:
                  Bart Van der Donck wrote:
                  >
                  >    var data = '1319842,847,16 20107\n';
                  >    data += '-1,-1,-1\n';
                  >    data += '-1,-1,-1\n';
                  >    data += '-1,-1,-1\n';
                  >    [...]
                  >    data += '-1,-1';
                  >
                  Please don't you ever suggest such junk here again.  The least that canbe
                  done is
                  >
                    var data = '1319842,847,16 20107\n'
                             + '-1,-1,-1\n'
                             + '-1,-1,-1\n'
                             ...
                             + '-1,-1';
                  No, it's only a matter of preference. None of these notations is
                  better/worse than the other.
                  >    // Split on end-of-line
                  >    var line = data.split('\n' );
                  >
                  That does not solve the OPs parsing problem at all.  This would:
                  >
                    var s = "1319710,847,16 20107 -1,-1,-1";
                    var lines = s.split(/\s+/);
                  As the OP writes himself, '\n' is his line separator. No need to use
                  '\s+' then.

                  --
                  Bart

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Reading an array of numbers

                    Bart Van der Donck wrote:
                    Thomas 'PointedEars' Lahn wrote:
                    >Bart Van der Donck wrote:
                    >> var data = '1319842,847,16 20107\n';
                    >> data += '-1,-1,-1\n';
                    >> data += '-1,-1,-1\n';
                    >> data += '-1,-1,-1\n';
                    >> [...]
                    >> data += '-1,-1';
                    >Please don't you ever suggest such junk here again. The least that can be
                    >done is
                    >>
                    > var data = '1319842,847,16 20107\n'
                    > + '-1,-1,-1\n'
                    > + '-1,-1,-1\n'
                    > ...
                    > + '-1,-1';
                    >
                    No, it's only a matter of preference. None of these notations is
                    better/worse than the other.
                    I think repeated `+=' is less efficient and harder to maintain than several
                    `+' in one assignment.
                    >> // Split on end-of-line
                    >> var line = data.split('\n' );
                    >That does not solve the OPs parsing problem at all. This would:
                    >>
                    > var s = "1319710,847,16 20107 -1,-1,-1";
                    > var lines = s.split(/\s+/);
                    >
                    As the OP writes himself, '\n' is his line separator. No need to use
                    '\s+' then.
                    It would appear that the original posting used the wrong separator. I have
                    read the original poster's clarification afterwards, since that came later
                    than your posting.


                    PointedEars
                    --
                    var bugRiddenCrashP ronePieceOfJunk = (
                    navigator.userA gent.indexOf('M SIE 5') != -1
                    && navigator.userA gent.indexOf('M ac') != -1
                    ) // Plone, register_functi on.js:16

                    Comment

                    Working...