Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi all !
I really need your help for a hint : I need the length of strings which are UTF-8 coded. I'm using Perl from Active state (5.8.8.822/Windows XP or 5.10.0.1004/Suse Linux 11.0) with the same "false" result. (I think I'm wrong, but i can't find where). for example: length('a') returns 1 : That's right length('à') returns 2 : That's wrong (I think it should return 1, because it's one CHARACTER long, although 2 BYTES because of UTF-8): When looking at documentation (perlfunc / length) : I read that : " Note the characters: if the EXPR is in Unicode, you will get the number of characters, not the number of bytes. To get the length of the internal string in bytes, use bytes::length(EXPR), see the bytes manpage. Note that the internal encoding is variable, and the number of bytes usually meaningless. To get the number of bytes that the string would have when encoded as UTF-8, use length(Encoding::encode_utf8(EXPR))" It seems to play the opposite role! Any Idea ? Thanks in advance Didier In reply to function length() in UTF-8 context by didess
|
|