Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

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


in reply to How do I get the Nth Character of a String?

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 Re: How do I get the Nth Character of a String?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://330762]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2021-04-16 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?