Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by gridlock (Novice)
on Feb 21, 2004 at 04:39 UTC ( #330762=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > How do I get the Nth Character of a String? - Answer 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?
[oiskuu]: I'm unfamiliar with android or SELinux. But I believe there is nothing of a kind. Unless you play with capabilities or build your own containers/ namespaces.
[davido]: I am not finding closing STDIN to be an adequate means of making getlogin return undef.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2017-06-23 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (554 votes). Check out past polls.