Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

How do I find the length of a string?

by vroom (Pope)
on Jan 11, 2000 at 23:27 UTC ( #1971=perlquestion: print w/replies, xml ) Need Help??

vroom has asked for the wisdom of the Perl Monks concerning the following question: (strings)

How do I find the length of a string?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I find the length of a string?
by vroom (Pope) on Jan 11, 2000 at 23:28 UTC
    length($string) returns the number of characters in a string.
    $foo = "quux"; $foolen = length $foo; # in this case, 4
Re: How do I find the length of a string?
by vrk (Chaplain) on Jun 04, 2007 at 12:03 UTC

    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.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2021-12-01 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (15 votes). Check out past polls.

    Notices?