String Character Length: Difference between revisions
Content deleted Content added
This is not the place to talk about __len__, and there is no need to link to the byte length from each language section |
Handling encoded strings |
||
Line 299: | Line 299: | ||
'''Interpreter:''' [[Python]] 2.4 |
'''Interpreter:''' [[Python]] 2.4 |
||
len() returns the length of a unicode string or plain ascii string. To get the length of encoded string, you have to decode it first: |
|||
<pre> |
|||
>>> len('ascii') |
|||
5 |
|||
>>> len(u'\u05d0') # the letter Alef as unicode literal |
|||
1 |
|||
>>> len('\xd7\x90'.decode('utf-8')) # Same encoded as utf-8 string |
|||
1 |
|||
</pre> |
|||
==[[Ruby]]== |
==[[Ruby]]== |