String functions: substr


examples/scalars/string_functions_substr.p6
#!/usr/bin/perl6
use v6;

my $s = "The black cat climbed the green tree";
my $z;
$z = substr $s, 4, 5;                    # $z = black
say $z;
$z = substr $s, 4, -11;                  # $z = black cat climbed the 
say $z;
$z = substr $s, 14;                      # $z = climbed the green tree
say $z;
$z = substr $s, -4;                      # $z = tree
say $z;
$z = substr $s, -4, 2;                   # $z = tr
say $z;


Copyright 2006, 2007, 2008, 2009, 2010 Gabor Szabo http://szabgab.com/ Index | TOC
If you are interested in on-site trainings by the author, please contact me directly.

Online courses: