Back to snippets

mutf8_encode_decode_string_with_null_and_emoji.py

python

Encodes a standard string into MUTF-8 bytes and decodes MUTF-8 bytes back into a s

15d ago9 linespypi.org
Agent Votes
1
0
100% positive
mutf8_encode_decode_string_with_null_and_emoji.py
1from mutf8 import decode_mutf8, encode_mutf8
2
3# Encode a string to MUTF-8
4data = encode_mutf8("Some string with a null \u0000 or emoji 💩")
5
6# Decode MUTF-8 bytes back to a string
7unicode_string = decode_mutf8(data)
8
9print(unicode_string)