dead Dung để làm gì
2014-03-01 05:25 · (0)
* aBir * Graham No idea
2014-02-27 02:59 · (0)
* Povilas * Graham Very impressive!
2014-02-27 02:31 (edited 2014-02-27 04:29 by Povilas ) · (0)
* Graham  
Xtscript does not have an array function but here is how to "fake" a simple array
first the function script
<!--parser:xtscript-->
#<!--
function array $d;$n;$nv;$sv;$fl=first;$m=read;$sep=|
var $o = -1
var $i = 0
if $m == count
var $n = 1000
else
var $n = ($n+1)
endif
if not $m == search
goto @l2
endif
if $fl == first
var $p = call strpos $haystack=$sep$d$sep;$needle=$sep$sv$sep 
else if $fl == last
var $p = call strrpos $haystack=$sep$d$sep;$needle=$sep$sv$sep
endif
if not $p
return -1
endif
@l1
if $o <= $p
var $oo = ($o+1)
var $o = call strpos $haystack=$sep$d$sep;$needle=$sep;$offset=$oo
var $i = ($i+1)
goto @l1
endif
return ($i-2)
@l2
if $m==count
 var $rv=($i-2)
else
delete $rv
endif
if $i > $n or not $o
 return $rv
endif
if $i < $n
 var $oo = ($o+1)
 var $o = call strpos $haystack=$d$sep;$needle=$sep;$offset=$oo
 var $i = ($i+1)
goto @l2
endif
if $m == read
var $val = call substr $val=$d;$start=$oo;$length=($o-$oo)
return $val
endif
if $m ==replace
var $arr1 = call substr $val=$d;$start=0;$length=$oo
var $arr2 = call substr $val=$d;$start=$o
return $arr1$nv$arr2
endif
if $m == insert
var $arr1 = call substr $val=$d;$start=0;$length=$oo
var $arr2 = call substr $val=$d;$start=$oo
return $arr1$nv$sep$arr2
endif
if $m == delete
var $arr1 = call substr $val=$d;$start=0;$length=($oo-1)
var $arr2 = call substr $val=$d;$start=$o
return $arr1$arr2
endif
endfunction
#-->
<!--/parser:xtscript-->

Copy code


Define the array
var $arr= banana|apple|orange|grape|lemon|mango
If you change the separator used in the array set $sep=new separator in your array function calls
Or to change it permanently change the default for $sep in the function script

To read a element in the array (read is the default mode so it can be omitted )
var $value = call array $d=$arr;$n=4;$m=read
Returns the 4th element (starting from 0) which is "lemon"

To replace an element in the array
var $arr=call array $d=$arr;$n=4;$nv=melon;$m=replace
Array is now "banana|apple|orange|grape|melon|mango"

To insert an element into the array
var $arr=call array $d=$arr;$n=4;$nv=rhubarb;$m=insert
Array is now "banana|apple|orange|grape|rhubarb|melon|mango "

To delete an element from the array
var $arr=call array $d=$arr;$n=4;$m=delete
Array is now "banana|apple|orange|grape|melon|mango"

To search for a value in the array and return the elements position
$sv is the value to search for
$fl is first or last occurrence default is first ( can be omitted )
var $value = call array $d=$arr;$sv=melon;$fl=first;$m=search
Returns "4" for "melon"
Returns "-1" if the value is not found

To count the elements in an array
var $value = call array $d=$arr;$m=count
Returns "5" (remember the first element is 0)
Note: Out of range values for $n will also return the element count
2014-02-24 00:01 (edited 2014-02-28 10:03 by Graham ) · (1)

Online: Guests: 2