index|substr

 1 #!/usr/bin/perl
 2 
 3 use strict;
 4 use warnings;
 5 
 6 $_ = 'duwanxkm,c.,df;oq123@#!@%$#^';
 7 my $d ='d';my $o = 'o';my $where =index($_,$o);print "$where\n";
 8 $where =index($_,$d,7);print "$where\n";
 9 $where =index($_,'y');print "$where\n";
10 my $lastword = rindex("%23%4546","%",2);print "$lastword\n";
11 
12 #15
13 #12
14 #-1
15 #3
16 #0
17 
18 my $sentence = 'very very long';
19 my $cut = substr ($sentence,index($sentence,'long'),3);substr ($sentence,index($sentence,'long'),3)='yoo!';print "$sentence\n$cut\n";
20 substr ($sentence,-12) =~ s/o/AAAAAA/g;print "$sentence\n";
21 
22 #very very yoo!g
23 #lon
24 #very very yAAAAAAAAAAAA!g
25 
26 my $new = substr ($sentence,3,10,"GOOOOO");print "$new\n$sentence\n";
27 
28 #y very yAA
29 #verGOOOOOAAAAAAAAAA!g

 

上一篇:04 设置字体


下一篇:组件(四)