By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Reading an array of numbers

P: n/a
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,1620107 -1,-1,-1

i want
line1 = 1319710,847,1620107
line2 = -1,-1,-1

PLZ HELP!
Jul 31 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
The Ax wrote:
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
It's not possible by default to read data from another domain:
http://en.wikipedia.org/wiki/Same_origin_policy

If you have the possibility to install Perl scripts, you might be
interested in a cross-domain AJAX call:
http://www.ajax-cross-domain.com/
instead of:
1319710,847,1620107 -1,-1,-1

i want
line1 = 1319710,847,1620107
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,1620107\n';
data += '-1,-1,-1\n';
data += '-1,-1,-1\n';
data += '-1,-1,-1\n';
data += '1986686,54,151953\n';
data += '738525,63,370092\n';
data += '1344192,41,43535\n';
data += '1647561,47,81344\n';
data += '-1,-1,-1\n';
data += '1344271,62,347527\n';
data += '887647,54,151408\n';
data += '-1,-1,-1\n';
data += '1551896,43,53020\n';
data += '1281239,44,59664\n';
data += '1700818,41,43035\n';
data += '-1,-1,-1\n';
data += '-1,-1,-1\n';
data += '1291525,31,15771\n';
data += '-1,-1,-1\n';
data += '-1,-1,-1\n';
data += '-1,-1,-1\n';
data += '427209,42,48164\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:
http://www.w3schools.com/jsref/jsref_split.asp

Hope this helps,

--
Bart
Jul 31 '08 #2

P: n/a
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,1620107 -1,-1,-1

i want
line1 = 1319710,847,1620107
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,1620107 -1,-1,-1 -1,-1,-1 -1,-1,-1
1986710,54,151953 738534,63,370092 1344203,41,43535 1647581,47,81344
-1,-1,-1 1344287,62,347527 887655,54,151408 -1,-1,-1 1551915,43,53020
1281250,44,59664 1700835,41,43035 -1,-1,-1 -1,-1,-1 1291539,31,15771
-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 myBackwardString = "";
while(myArr.length) {
myBackwardString += myArr.pop()+',';
}
document.write(myBackwardString);

Good Luck!
Kev
Jul 31 '08 #3

P: n/a
kaydub wrote on 31 jul 2008 in comp.lang.javascript:
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,1620107 -1,-1,-1

i want
line1 = 1319710,847,1620107
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,1620107 -1,-1,-1 -1,-1,-1 -1,-1,-1
1986710,54,151953 738534,63,370092 1344203,41,43535 1647581,47,81344
-1,-1,-1 1344287,62,347527 887655,54,151408 -1,-1,-1 1551915,43,53020
1281250,44,59664 1700835,41,43035 -1,-1,-1 -1,-1,-1 1291539,31,15771
-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 myBackwardString = "";
while(myArr.length) {
myBackwardString += myArr.pop()+',';
}
document.write(myBackwardString);
KISS:

var myString = '1319851,847,1620107 -1,-1,-1 -1';
var myBackwardString = myString.split(',').reverse().join(',');
document.write(myBackwardString);


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 31 '08 #4

P: n/a
SAM
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,1620107 -1,-1,-1

i want
line1 = 1319710,847,1620107
line2 = -1,-1,-1
The source code is exactly as you want.

Once on the page, type in addresses bar :

javascript:document.body.innerHTML="<pre>"+documen t.body.innerHTML+"<\/pre>"

--
sm
Jul 31 '08 #5

P: n/a
On Jul 31, 8:14*am, SAM <stephanemoriaux.NoAd...@wanadoo.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,1620107 -1,-1,-1
i want
line1 = 1319710,847,1620107
line2 = -1,-1,-1

The source code is exactly as you want.

Once on the page, type in addresses bar :

javascript:document.body.innerHTML="<pre>"+documen t.body.innerHTML+"<\/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
Jul 31 '08 #6

P: n/a
Bart Van der Donck wrote:
The Ax wrote:
>instead of:
1319710,847,1620107 -1,-1,-1

i want
line1 = 1319710,847,1620107
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,1620107\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,1620107\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,1620107 -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
Jul 31 '08 #7

P: n/a
SAM
The Ax a écrit :
On Jul 31, 8:14 am, SAM <stephanemoriaux.NoAd...@wanadoo.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,1620107 -1,-1,-1
i want
line1 = 1319710,847,1620107
line2 = -1,-1,-1
The source code is exactly as you want.

Once on the page, type in addresses bar :

javascript:document.body.innerHTML="<pre>"+docume nt.body.innerHTML+"<\/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:alert(document.body.innerHTML);
as this is too with :
javascript:document.body.innerHTML=document.body.i nnerHTML.split('\n').join('<br>');
or this one :
javascript:document.body.innerHTML=document.body.i nnerHTML.replace(/\n/g,'<br>');

In your page that could give :
document.getElementById('results').innerHTML=trucb idule.split('\n').join('<br>');
or :
document.getElementById('results').innerHTML=trucb idule.replace(/\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
Jul 31 '08 #8

P: n/a
Thomas 'PointedEars' Lahn wrote:
Bart Van der Donck wrote:
>* * var data = '1319842,847,1620107\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,1620107\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,1620107 -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
Aug 1 '08 #9

P: n/a
Bart Van der Donck wrote:
Thomas 'PointedEars' Lahn wrote:
>Bart Van der Donck wrote:
>> var data = '1319842,847,1620107\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,1620107\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,1620107 -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 bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 1 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.