Basic HTML version of Foils prepared Sept 20 97

Foil 51 The substr Function

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


$partstring = substr($string, $start, $length); # returns in $partstring the partial string starting at position $start of at most $length characters
  • Missing $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
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"



© 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 Sun Sep 21 1997