Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

Selecting a substring in Icon

Tech Computer Center logo

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.

Next: Using csets to describe sets of characters in Icon
See also: Using strings in Icon
Previous: Finding the size of an Icon string
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437
Home: About New Mexico Tech

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
QR two-dimensional bar code