News flash: I'm going to Australia in February, so this Web site may be switched off at any time.


How Icon positions are numbered

In Icon, the characters in a string are identified by their position, counting from 1. The positions refer to the gaps between the characters, not to the characters themselves. Positive numbers count from the left starting at 1, and nonpositive numbers count from the right starting at 0. For example, the positions of the gaps in the string "abc" are numbered like this:

   -3    -2    -1     0
    +-----+-----+-----+
    |  a  |  b  |  c  |
    +-----+-----+-----+
    1     2     3     4
So position 1 (or -3) refers to the position before the first character; position 2 (or -2) refers to the position before the second character; and so on. Position 0 is always the end of the string.
Next: Finding the size of an Icon string
See also: Using the Icon programming language
Previous: Reading an input line in Icon

John W. Shipman, john@nmt.edu