Snippets tagged “encoding”
10 snippets use this tag.
- Best way to convert string to bytes in Python 3?Python
In Python 3, you can convert a string to bytes using the bytes function.
- Convert bytes to a stringPython
To convert a byte object into a string, you can use the decode() method.
- Encoding as Base64 in JavaJava
To encode a string as Base64 in Java, you can use the java.util.Base64 class. Here's an example of how you can use the Base64 class to encode a string:
- How to convert an image to Base64 encodingPHP
To convert an image to base64 encoding in PHP, you can use the base64_encode() function
- How to fix: "UnicodeDecodeError: 'ascii' codec can't decode byte"Python
The "UnicodeDecodeError: 'ascii' codec can't decode byte" error occurs when trying to decode non-ASCII bytes using the ASCII codec.
- Java Byte Array to String to Byte ArrayJava
To convert a byte array to a string and back to a byte array in Java, you can use the getBytes method of the String class and the getBytes method of the Charset class.
- Unicode (UTF-8) reading and writing to files in PythonPython
To read a file in Unicode (UTF-8) encoding in Python, you can use the built-in open() function, specifying the encoding as "utf-8".
- UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)Python
This error is raised when trying to encode a Unicode string using the ASCII codec, and the string contains a character that is not within the ASCII range (0-127).
- Why can't Python parse this JSON data?Python
Without a specific code snippet and the JSON data that is causing issues, it is difficult to determine why Python is unable to parse the data.
- Working with UTF-8 encoding in Python sourcePython
Here is a code snippet that demonstrates how to work with UTF-8 encoding in a Python source file: