Selecting a substring in Icon |
|
A single character can be extracted from a string s
by using the expression ``s[i]'',
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,
then ``line[2]'' is the second character of the line.
Any part of a string s can be extracted by using the form
``s[i:j]'',
where i and j
are the starting and ending positions. For example, the expression
``line[4:6]'' returns the fourth and fifth characters
of ``line'', and
line[-2:0]
returns the last two characters of ``line''.
You can also use the form
``s[i+:n]'' to extract
the n characters of s starting at position i.
For example,
line[5+:3]
returns the three characters starting at position 5 of line.
|
John Shipman, john@nmt.edu
Last updated: 1996/01/06 21:12:57 UT URL: http://www.nmt.edu/tcc/help/lang/icon/substring.html |
|