LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-29-2004, 03:39 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
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
 
Old 10-29-2004, 04:55 PM   #2
Slaxx
LQ Newbie
 
Registered: Sep 2004
Location: Purdue University
Distribution: Slackware 10.0
Posts: 11

Rep: Reputation: 0
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].
 
Old 10-30-2004, 07:22 PM   #3
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Original Poster
Rep: Reputation: 30
hey thanks, i thought it was that easy.


-djgerbavore
 
Old 10-31-2004, 07:23 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

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

substr($myStr, 3);

Particulary if used in big loops
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse String in a Bash script jimwelc Linux - Newbie 8 11-09-2012 07:47 AM
c++ parse date string?? blizunt7 Programming 25 05-18-2006 03:12 PM
Parse --static string no delimiters DaFrEQ Programming 2 04-08-2005 02:06 PM
Parse RPM version string in Bash jimwelc Linux - Newbie 1 02-28-2005 05:22 PM
C++ and C# Parse a string into a numerical type exodist Programming 8 02-23-2004 06:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration