indextoitem
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | indextoitem [2006/08/01 03:45] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | # $EPIC: indextoitem.txt, | ||
+ | ======Synopsis: | ||
+ | $indextoitem(< | ||
+ | $itemtoindex(< | ||
+ | |||
+ | ======Technical: | ||
+ | These functions are used to convert between array item numbers are index | ||
+ | numbers. | ||
+ | |||
+ | Item numbers are counted incrementally as items are added to an array, | ||
+ | starting at 0 (zero). | ||
+ | if there are 5 items in an array, the next item that may be added is item | ||
+ | number 5 (remember that we count from zero... 5 items is 0..4). | ||
+ | |||
+ | Index numbers represent each items position in the array when sorted. | ||
+ | Items are sorted based on their ascii values. | ||
+ | alphabetical; | ||
+ | letters are sorted after all lowercase letters. | ||
+ | algorithm similar to the $[[sort]]() function' | ||
+ | |||
+ | ======Practical: | ||
+ | The $__indextoitem__() function converts an index number in the given array | ||
+ | to its corresponding item number; $__itemtoindex__() does just the opposite. | ||
+ | This is mostly useful in conjunction with $[[igetitem]]() or $[[ifinditem]](), | ||
+ | allowing an array to be dealt with in a logical order. | ||
+ | |||
+ | ======Returns: | ||
+ | < | ||
+ | -2 | ||
+ | -1 | ||
+ | > -1 item number corresponding to given index number (and vice verse) | ||
+ | </ | ||
+ | |||
+ | ======Examples: | ||
+ | < | ||
+ | $setitem(booya 0 hello) | ||
+ | $setitem(booya 1 goodbye) | ||
+ | $itemtoindex(booya 0) | ||
+ | $indextoitem(booya 1) | ||
+ | $itemtoindex(foobar 0) returns -1 | ||
+ | $itemtoindex(booya 100) | ||
+ | </ | ||
indextoitem.txt · Last modified: 2006/08/01 03:45 by 127.0.0.1