Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Answer: How do I pull n characters off the front of a string?

( #75138=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I pull n characters off the front of a string? contributed by arturo

Bah! Why use regexes when there's a faster function designed for the purpose? =)

#assuming $n contains the number ... my $first_n = substr($string, 0, $n); #to grab $n off the end my $last_n = substr($string, -1, $n);

Comment on Answer: How do I pull n characters off the front of a string?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-07-04 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls