in reply to How does the built-in function length work?
length doesn't know anything about encodings. It counts the characters in the string, whether those characters happen to be bytes, Unicode code points or something entirely different.
If you pass encoded text to it (bytes), it will count the bytes.
If you pass decoded text to it (Unicode code points), it will count the Unicode code points.
Bytes "\xC9\x72\x69\x63" String: C9 72 69 63 Length: 4 Unicode code points "\N{LATIN CAPITAL LETTER E WITH ACUTE}ric" String: C9 72 69 63 Length: 4 Unicode code points "\N{LATIN CAPITAL LETTER E WITH ACUTE}ric\N{RIGHT SINGLE QUOTATION MAR +K}s" String: C9 72 69 63 2019 73 Length: 6
There are many ways of creating each of the above strings. I just listed one as an example. It doesn't matter how the string is created.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How does the built-in function length work?
by PerlOnTheWay (Monk) on Feb 10, 2012 at 01:37 UTC | |
by chromatic (Archbishop) on Feb 10, 2012 at 02:23 UTC | |
by ikegami (Patriarch) on Feb 12, 2012 at 04:04 UTC |