Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: The “real length" of UTF8 strings

by moritz (Cardinal)
on Sep 23, 2008 at 20:35 UTC ( [id://713305]=note: print w/replies, xml ) Need Help??


in reply to Re: The “real length" of UTF8 strings
in thread The “real length" of UTF8 strings

In general the correlation between byte length in UTF-8 and visual character width is only a weak one.

For example many european non-ASCII-characters are printed with visual width of only one character, but encoded as two bytes. The Euro sign is even encoded as three bytes, and still printed with a width of only one.

Replies are listed 'Best First'.
Re^3: The “real length" of UTF8 strings
by betterworld (Curate) on Sep 23, 2008 at 21:54 UTC

    You're right. I misunderstood the question and did not realize that we are looking for the "visual length".

    Well, I think it depends on the font then, doesn't it?

      Well, I think it depends on the font then, doesn't it?

      Maybe, but there are double-width characters that even fixed-width fonts display with the width of two normal characters (like the ones in the OP).

      Yes betterworld, I should have choosen a better title like "the visual length of UTF8 strings" instead of the "real length" which leads to confusion.

Re^3: The “real length" of UTF8 strings
by Anonymous Monk on Sep 24, 2008 at 04:18 UTC

    You're right, the correlation between visual length and the actual number of characters is weak, and maybe only font dependent...

    But when I print these strings with both chinese and ASCII characters using the mysql command (SELECT * FROM...), it prints an array on stdout and is absolutely not confused with the visual and character lengths.

    That's why I think the solution must exist ^_^*

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-23 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found