Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / How to I get the text stored in an array?

Author
Message
Mykyl66
User Offline
Joined: 30th May 2019
Location:
Posted: 5th Jun 2019 16:39
How to I get the text stored in an array? I want to print it to screen. I can get the index no problem but I have no idea how to retrieve the text stored at that index.

One example from the docs is this. However it returns the index and not the actual text stored. It prints 3 to screen not the name stored there.

Any help please?

Thank you

names as string [ 5 ] = [ "", "lee", "rick", "paul", "dave", "adam" ]
names.sort ( )
do
for i = 1 to names.length
print ( names [ i ] )
next i
print ( "" )
index = names.find ( "lee" )


print ( "lee is at index = " + str ( index ) )


sync ( )
loop
Mykyl66
User Offline
Joined: 30th May 2019
Location:
Posted: 5th Jun 2019 16:51
I'm not sure if my post succeeded as this looks blank. I figured it out myself though. Thank you.
KeithC
Senior Moderator
13
Years of Service
User Offline
Joined: 27th Oct 2005
Location: Michigan
Posted: 5th Jun 2019 18:18
Apologies. Newer Member's Posts are vetted by hand, until you reach the secret post count.
-Keith
Mykyl66
User Offline
Joined: 30th May 2019
Location:
Posted: 5th Jun 2019 19:04
No problem.

If any other new folks are wondering how. I got the text by changing this line
print ( "lee is at index = " + str ( index ) )

to this

print ( "Yup. I found " + (names[index]) + " at index " + str ( index ) )

cheers
MikeHart
16
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 6th Jun 2019 11:09
Hi Mike, nice to see you.

Just some heads up, Array.Length actually returns the last index of an array. And arrays start indexing from 0.

Cheers
Michael

Login to post a reply

Server time is: 2019-07-18 09:01:56
Your offset time is: 2019-07-18 09:01:56