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 / String to array

Author
Message
theUsual
9
Years of Service
User Offline
Joined: 13th Jul 2015
Location: Norway
Posted: 20th Jul 2015 17:45 Edited at: 20th Jul 2015 17:56
I've used the command GetStringToken() to extract a substring separated by a character. But what do I do if I want to split a word into a character array?

EDIT: Never mind. I found some functions called left(), right() & mid(), i think they'll do the job. Not easy to find though.

Daniel
theUsual
9
Years of Service
User Offline
Joined: 13th Jul 2015
Location: Norway
Posted: 20th Jul 2015 18:14
Working code:
okee
10
Years of Service
User Offline
Joined: 1st May 2014
Location: Ireland
Posted: 21st Jul 2015 00:34
Also another way

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 25th Jul 2015 20:48
A suggestion, this is an efficiency bit to avoid re-evaluting math expressions and such in the for loop.

theUsual's code:


okee's code:


theUsual's code is actually probably the one that would execute faster. It predefines the array size and then just sets values.

okee's code requires a function call (ar.insert) each loop. That call has to resize the array each time in order to add the new element. Each resize operation does a memory allocation for the new size, copies the existing values from the old array, stores the new value and then (hopefully) clears the memory for the old array.

But, it is a bit more 'elegant'.

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-11-21 21:11:01
Your offset time is: 2024-11-21 21:11:01