text manipulation

Get help using Construct 2

Post » Fri Nov 18, 2011 12:21 pm

im having a hard time figuring this out, because i never used this string functions before...

i want to loop thru this string and get every value in an array

4|5654|8948|44|

this i found out

tokencount(varload,"|") - 1 = number of seperators

find(varload, "|") = first part of the string before "|"

but now how do i get to the next value of the seperator?
ive seen some examples but i dont understand, can anybody explain how and how its works?

if i know how to loop thru all these i should also be able to put then in an array i guess







ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Fri Nov 18, 2011 7:57 pm

vtrix, is this what you're looking for?

http://dl.dropbox.com/u/38038537/StringToArray_example.capx
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Fri Nov 18, 2011 8:17 pm

find(varload, "|") = position of the first | in the string

basically you get each token ( = part between separators) by incrementing an iterator
the iterator can be a simple variable or a loopindex

Code: Select all
global iterator = 0
every 5.0 seconds :
    set text to tokenat(varload,iterator,"|")
    add 1 to iterator


or

Code: Select all
for "itLoop" from 0 to tokencount(varload,"|")-1
    append to text : tokenat(varload,loopindex("itLoop"),"|")
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346


Return to How do I....?

Who is online

Users browsing this forum: abdalghani, imothep85, LeFuji, Marxally, Virpoja and 23 guests