Perl Monk, Perl Meditation | |
PerlMonks |
Trying to determine the output length of a Unicode stringby pierswalter (Initiate) |
on Sep 25, 2011 at 15:08 UTC ( [id://927755]=perlquestion: print w/replies, xml ) | Need Help?? |
pierswalter has asked for the wisdom of the Perl Monks concerning the following question: I'm trying to print Unicode text in tabulated columns (assuming a fixed width font). To do so, I calculate the length of various strings using Perl's length() function. This does not work for me for two reasons (the first one being irrelevant in my specific case, I just include it for completeness' sake for the archives): 1. length("\x{341f}") returns 1, which is semantically correct. 2. Am I using the wrong approach? Is there a different function than length() that would return the number of output characters (i.e. 1 in the case of "\x{0075}\x{0308}")? So far, the only solution I came up with is to convert each string into Unicode normalization form C before calculating its output length, but that seems more complicated than I feel this should be. Here is an example that demonstrates the problem:
Thanks for your thoughts.
Back to
Seekers of Perl Wisdom
|
|