Basic HTML version of Foils prepared March 30 97

Foil 48 substr (Chapter 15 of Llama Book)

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


1 $partstring = substr($string,$start,$length); # returns in $partstring the partial string starting at position $start (=0 for first character in $string) and of at most $length characters
  • Missing out $length or a huge value for $length returns all characters from starting position to end of $string
  • Negative values of $start count backwards from end character in $string
  • $endchar=substr($string,-1,1); # returns last character in $string
2 substr($string,$start,$length)= $new; # replaces extracted substring with characters in $new which need not be of same length as original
  • $class="CPS600";
  • substr($class,3)="616"; # leads to $class="CPS616"

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