Community discussions

MikroTik App
 
-headstrong-
Member
Member
Topic Author
Posts: 377
Joined: Thu Jun 05, 2008 8:04 pm
Location: South Africa

getting value of array at position 2

Wed Feb 03, 2010 9:36 pm

Hi Guys

What is the syntax to select the 3rd value of an array of 5 elements? ie return value C in the below example?

:local myStr "A,B,C,D,E";
:put [:typeof $myStr];
:local myArr [:toarray $myStr];
:put [:typeof $myArr]

:log info [:find 3 $myArr]?????
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: getting value of array at position 2

Wed Feb 03, 2010 9:41 pm

[admin@MikroTik] > :local myStr "A,B,C,D,E"; :local myArr [:toarray $myStr]; :local third [:pick $myArr 2]; :put $third;
C
Use :pick to select array elements, the index is zero-based.
 
-headstrong-
Member
Member
Topic Author
Posts: 377
Joined: Thu Jun 05, 2008 8:04 pm
Location: South Africa

Re: getting value of array at position 2

Wed Feb 03, 2010 10:12 pm

perfect thanks

Who is online

Users browsing this forum: No registered users and 7 guests