Selecting a substring in Icon
A single character can be extracted from a string s
by using the expression ``
where i is the position
just to the left of the character (see
`How Icon positions are numbered').
For example, if variable ``
line'' contains a line of text,
line'' is the second character of the line.
Any part of a string s can be extracted by using the form
where i and j
are the starting and ending positions. For example, the expression
line[4:6]'' returns the fourth and fifth characters
line[-2:0]returns the last two characters of ``
You can also use the form
s[i+:n]'' to extract
the n characters of s starting at position i.
line[5+:3]returns the three characters starting at position 5 of
John Shipman, email@example.com
Last updated: 1996/01/06 21:12:57 UT