Scanning strings in Icon and Unicon
Unicon inherits this domain control structure from its immediate predecessor, Icon. In Icon and Unicon, a control structure called string scanning is invoked by the s ? expr
syntax. Within expr
, the string s
is the scanning subject and it is referenced by a global keyword called &subject
. Within the subject string, a current analysis position, which is stored in the &pos
keyword, denotes the index location in the subject string where that string is being scanned. The position starts at the beginning of the string and can be moved back and forth, typically working its way toward the end of the string. For example, in the following program, s
contains "For example, suppose string s contains"
:
procedure main()
s := "For example, suppose string s contains"
s ? {
tab(find("suppose"))
write("after tab()")
}
end
Now, let’s say we were adding the above-mentioned scanning...