LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Parse a perl string (https://www.linuxquestions.org/questions/programming-9/parse-a-perl-string-248877/)

djgerbavore 10-29-2004 03:39 PM

Parse a perl string
 
want to only show hte last four or so char of a perl string .


how do i do that? $myStr = "1234567";
i want to just show 4567.

how can i do this?


thanks

Slaxx 10-29-2004 04:55 PM

substr($myStr, -4, 4);

or generically: substr(string, pos, number);

This function returns [number] characters from [string], starting at position [pos]. If [pos] < 0, it starts that many characters from the end, e.g. -4 means start 4 characters from the end of [string].

djgerbavore 10-30-2004 07:22 PM

hey thanks, i thought it was that easy.


-djgerbavore

Cedrik 10-31-2004 07:23 AM

It may be a little more efficient to use in this case :

substr($myStr, 3);

Particulary if used in big loops


All times are GMT -5. The time now is 03:07 AM.