Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1052

UTF-16 as sequence of code units in python

$
0
0

I have the string 'abç'which in utf8 is b'ab\xc3\xa7'

I want it in utf-16, but not this way :

b'ab\xc3\xa7'.decode('utf-8').encode('utf-16-be')

which gives me

b'\x00a\x00b\x00\xe7'

the answer I want is the utf-16 code units, that is, a list of int :

[32, 33, 327]

Is there any straightforward way to do that?

And of course, the reverse. Given a list of ints which are utf-16 code units, how do I convert that to utf-8?


Viewing all articles
Browse latest Browse all 1052

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>