Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: How do I get the Nth Character of a String?

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

Q&A > strings > How do I get the Nth Character of a String? contributed by gridlock

The substr function:
Remember the strings are Zero-Based - i.e. - the first character is character '0', the second character is character '1' and so on....

By that logic, the n-th character is character '(n-1)'

So you're n-th character can be extracted as
$nth = substr($string, n-1, 1);

Comment on Answer: How do I get the Nth Character of a String?
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 avoiding work at the Monastery: (4)
As of 2015-07-04 07:01 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 (58 votes), past polls