Basic HTML version of Foils prepared March 30 97

Foil 47 index and rindex (Chapter 15 of Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


1 $loc=index($string,$substr); # returns in $loc the location(first character in $string is location 0) of first occurrence of $substr in $string.
  • If $substr is not located, return -1
2 $loc=index($string,$substr,$firstloc); # will return $loc which is at least as large as $firstloc
  • Use to find multiple occurrences, setting $firstloc as 1+ previously found location
3 rindex($string,$substr,$lastloc) is identical to index except scanning starts at right (end) of string and not at start. All locations still count from left but if you give a third argument $lastloc, the returned $loc will be at most $lastloc in value

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Sep 6 1997