Perl

substr

$str = "ABCDEFG1234567";
$a = substr $str, 0, 5;
print $a;        # print out ABCDE

length

$str = "ABC";
print length $str;      #print out 3

uc/lc

$str = "ABCabc";
print uc $str;    #ABCABC
print lc $str;    #abcabc

index

$str = "ABCDEFG";
$sub = "EFG";
print (index ($str, $sub));     #4
print (index ($str, $sub, 2));     #2 -- start searching from "C" in "ABCDEFG

rindex

$str = "ABCDEFG";
$sub = "EFG";
print (rindex ($str, $sub));     #2
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License