473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Reading an array of numbers

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
9 1421
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Brad Marts | last post by:
I have a file containing numbers stored in binary form and information in ascii which tells me what kind of numbers they are (int, float, double, etc.). I want to be able to read in the numbers and...
2
by: pesso | last post by:
I have a string that contains the following: string s = "130,41,43,178,41,17,6,78,244,35,202,144,115"; They are comma separated byte numbers, and I need to initialize my byte array with them....
10
by: nuke1872 | last post by:
Hello guys, I have a file names network.txt which contains a matrix. I want to read this matrix as store it as an array. I am new to stuff like these...can anybody help me out !! Thanks nuke
6
by: Nick | last post by:
Hiya, Am having a few problems with StreamReader. I'm trying to open a text file, and read 5 columns, and put them into an array, and then do a calculation and read the next line of data, and...
32
by: Bill Cunningham | last post by:
I am interested in writing a numeric text reader. This only reads numbers of securities and stores them. Nice practice. I have determined that these functions are needed. isalpha, isdigit,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.