Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Answer: How do I get the Nth character of a string?

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

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

Use substr with a length of one. The character numbering is zero based so the first character in the string is the 0th element.
$str = "123456789"; $first = substr($str, 0, 1); #returns the first character $third = substr($str, 2, 1); #returns the third character

Comment on Answer: How do I get the Nth character 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 taking refuge in the Monastery: (8)
As of 2015-07-06 23:53 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 (85 votes), past polls