Programming Basics

  Home arrow Programming Basics arrow Perl String Processing Functions
PROGRAMMING BASICS

Perl String Processing Functions
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating:  stars stars stars stars stars / 0
    2012-04-25

    Table of Contents:
  • Perl String Processing Functions
  • The substr() Function

  •  
     

    SEARCH CODEWALKERS

    Perl String Processing Functions


    (Page 1 of 2 )

    In this second part of a three-part article series on string processing in Perl, you will learn about the rindex() and substr() functions. This article is excerpted from, teh book Beginning Perl, Second Edition, written by James Lee (Apress; ISBN-10: 159059391X)

    The rindex() Function

    The rindex() function is similar toindex()except that it searches the string from right to left (instead of left to right). The syntax is similar:

    rindex(string, substring)

    This function searches right-to-left through the string searching for the substring. It returns the 0-based index of where the substring is in the string, or –1 if the substring is not found.

    An important note: even though this function searches through the string from right to left, the 0th character of the string is still the left-most character.

    This invocation:

    rindex('David Gilmour', 'i')

    searches from the right-hand side of “David Gilmour” looking for the substring “i”. It finds it at position 7 (the “i” in “Gilmour”).

    This function also has an optional third argument that is the character position from which it begins looking for the substring. This invocation:

    rindex('David Gilmour', 'i', 6)

    starts at position 6 (the “G” in “Gilmour”) and looks right to left for an “i” and finds it at position 3.

    More Programming Basics Articles
    More By Apress Publishing

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - The Transliteration Operator in Perl
    - Perl String Processing Functions
    - Perl String Processing
    - Control Flow Constructs: Loops Conclusion
    - Loop Control Constructs
    - Control Flow Constructs: the For and Foreach...
    - Loops and Control Flow Constructs
    - Expression Modifiers for Perl Control Flow C...
    - Logical Operators and Control Flow Constructs
    - Comparing Strings with Control Flow Construc...
    - Perl Operators and Control Flow Constructs
    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP

    Developer Shed Affiliates

     



    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap