Perl 5 String Functions : String « String « Perl






Perl 5 String Functions

     

Function          Syntax                                                        Description

chomp             chomp($scalar);                                               Removes only a newline character from the end of a string

chop              chop($scalar);                                                Removes the last character of each element of the input list

chr               chr(number);                                                  Translates a number into a character

index             index(searchString, substring, beginningSearchPosition);      Returns the first position of a substring

join              join(delimiter, list);                                        Creates a single delineated string from an input list

lc                lc(expression);                                               Changes all the characters in the expression to lowercase

lcfirst           lcfirst(expression);                                          Changes only the first character of the expression to lowercase

length            length(expression);                                           Returns the number of characters in a string

ord               ord(expression);                                              Converts ASCII characters into their numeric value

pack              pack TEMPLATE, inputList;                                     Takes one or more character codes and translates the corresponding character(s) to the format specified

rindex            rindex (searchString, substring, startPosition);              Returns the last position of a substring

split             split(/pattern/,expression, maxSplit);                        Separates the expression into parts

s/(substitute)    $searchString =~ s/oldPattern/newPattern/;                    Substitutes one string for another string

substr            substr(expression,startingPosition,length);                   Returns or modifies a substring

tr (translate)    $input =~ tr/searchString/replacementString/                  Exchanges each occurrence of a character in the search string with its matching character in the replacement string

uc                uc(expression);                                               Changes all the characters in the expression to uppercase

ucfirst           ucfirst(expression);                                          Changes only the first character of the expression to uppercase

   
    
    
    
    
  








Related examples in the same category

1.String Operations
2.String Operators: the right and wrong ways to perform an equivalence check on a string:
3.String plus
4.String variable
5.Strings are normally delimited by a matched pair of either double or single quotes.
6.ASCII Character Codes
7.A string is a sequence of bytes (characters) enclosed in quotes.
8.Calculation on string
9.Use print to output string
10.Append two string value
11.Using ~ operator to check if a scalar is a string type variable
12.String Literals
13.String operators
14.String value reference