6.1.10:Negative Indexes in Chunk Expressions

チャンク表現式内でインデックスをたどる

To count backwards from the end of the value instead of forward from the beginning, specify a negative number. For example, the number -1 specifies the last chunk of the specified type, -2 specifies the next-to-last chunk, and so forth. The following statements all include valid chunk expressions:

値の始めから順に数えるのではなく終わりから逆に数えるには、負数を指定します。例えば、ー1という数は指定したチャンク形式の最後のチャンクを、ー2は最後のチャンクの前のチャンクを、等々と指定することになります。次のステイトメントは全て正しいチェンク表現式を含んでいます。

get item -1 of "feather, ball, cap" -- yields "cap"
「feather,ball,cap」の三つのアイテムのー1番目のアイテム;つまり「cap」

get char -3 of "ABCD" -- yields "B"
「ABCD」の四つのキャラクタのー3番目のキャラクタ;つまり「B」