How to find number of characters in a unicode string?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Sep 18 16:29:20 EDT 2006


In <20060918221814.08625ea2.randhol+valid_for_reply_from_news at pvv.org>,
Preben Randhol wrote:

> If I use len() on a string containing unicode letters I get the number
> of bytes the string uses. This means that len() can report size 6 when
> the unicode string only contains 3 characters (that one would write by
> hand or see on the screen). Is there a way to calculate in characters
> and not in bytes to represent the characters.

Yes and you already seem to know the answer:  Decode the byte string and
use `len()` on the unicode string.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list