File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ # Method encode() returns an encoded version of the string
3+ initial_string = 'Hello there!'
4+ encoded_string = initial_string .encode ('utf-32' )
5+
6+ # To choose the right Codec for needed language go to the page:
7+ # docs.python.org/3.7/library/codecs.html
8+ # Or choose 'ut-32' as standard for all languages
9+
10+ print ('Encoded string of "' , initial_string , '" is: ' )
11+ print (encoded_string )
12+
13+ # To decode string we need to use decode function
14+ decoded_string = b'\xff \xfe \x00 \x00 H\x00 \x00 \x00 e\x00 \x00 \x00 l\x00 \x00 \x00 l\x00 \x00 \x00 o\x00 \x00 \x00 \x00 \x00 \x00 t\x00 \x00 \x00 h\x00 \x00 \x00 e\x00 \x00 \x00 r\x00 \x00 \x00 e\x00 \x00 \x00 !\x00 \x00 \x00 ' .decode ('utf-32' )
15+ print (decoded_string )
16+
17+ # It is possile to use "Fill paragraph" option to show long string in the screen
18+ decoded_string = b'\xff \xfe \x00 \x00 H\x00 \x00 \x00 e\x00 \x00 \x00 l\x00 \x00 \x00 l\x00 \x00 \x00 o\x00 \x00 \x00 ' \
19+ b'\x00 \x00 \x00 t\x00 \x00 \x00 h\x00 \x00 \x00 e\x00 \x00 \x00 r\x00 \x00 \x00 e\x00 \x00 \x00 !\x00 \x00 \x00 ' \
20+ b'' .decode ('utf-32' )
21+ print (decoded_string )
You can’t perform that action at this time.
0 commit comments