Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Answer: How do I find the length of a string?

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

Q&A > strings > How do I find the length of a string? contributed by w-ber

Since Perl 5.6, Perl has had Unicode support, which manifests itself as UTF-8 encoded strings. If you want to find out how many characters a string has, simply use length($string). It just works.

However, if, for some reason, you need to find out how many bytes a string uses (which may be different from how many UTF-8 characters the string has):

use bytes; my $len = bytes::length($string);

Unless you know what you are doing, better steer clear of the latter. Use the former. (See perlunicode for more information.)

Comment on Answer: How do I find the length of a string?
Select or 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 surveying the Monastery: (15)
As of 2015-07-02 12:48 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 (37 votes), past polls