Problem Python UnicodeEncode Error: Cannot decode - python-3.x

I want to convert the byte data b'\u1eb9' back to a utf-8 character but failed.
Why i can encode a unicode character to a byte data but cannot reverse the process?

I use Sublime Text, but after that i tried this code on VS and it work so i think the system build of sublime text lack something. I add the "env": { 'PYTHONIOENCODING": "utf-8" } and it work.

Related

How to print a UTF-8 unicode string as EBCDIC in PL/I

How can I instruct PL/I to print a UTF-8 value as EBCDIC. Is there a "trick" in PL/I or do I have to call the z/OS unicode services to convert the UTF-8 value?
PUT SKIP EDIT('VAR: ',VAR) (A,A);
Using the above instruction gives unreadable output.
VAR: & (!¢
Try UTF8TOCHAR, which appears to be new with IBM Enterprise PL/I version 5.
PUT SKIP EDIT('VAR: ',UTF8TOCHAR(VAR)) (A,A);
That's just freehand, but I think you get the idea.

python reverse unicode text into readable

i believe i have similar problem to this how to convert unicode text to utf8 text readable? but i want a python 3.7 solution to it
i am a complete newbie, i have some experience with python so i am trying to use it to make a script that will convert a Unicode file into the previous readable text it was.
the file is a bookmark file i have recovered using easeusa then i opened the bookmark file and it is writen in unicode something like "&PŽ¾³kÊ
k-7ÄÜÅe–?XBdyÃ8߯r×»Êã¥bÏñ ¥»X§ÈÕÀ¬Zé‚1öÄEdýŽ‹€†.c"
whereas previously is said something like " "checksum": "112d56adbd0caa2b3693bb0442dd16ff",
"roots": {
"bookmark_bar": {
"children":"
fyi when i click save as for the unicode bookmark file, for unicode it has ANSI and not utf-8 maybe it was saved us ANSI, i might be waffling here but i'm just trying to give you all the information you might need to help me
i am a newbie who depressingly need help
This text isn't "Unicode". It's simply gibberish.
This file has been corrupted -- it may have been overwritten with other data before you were able to recover it. It is unlikely to be recoverable.

Node writes files with an encoding unrecognised by Sublime Text

When writing files with Node's fs's writeFileSync command, Sublime Text is unable to determine the correct character encoding.
Even when I explicitly define the encoding in the options:
fs.writeFileSync( '/path/to/file', 'some string', {encoding:'utf-8'});
In order to encode it as UTF-8, I have to File > Save with Encoding in Sublime to get it to recognise the correct encoding.
My hunch is that the problem is with Node, not Sublime, as I have encoding issues reading the file back into Node when special characters are present.
I'm using Sublime Text Build 3065.
Any ideas as to what's going on?
EDIT
Apologies, I forgot to mention that I use this command in the Sublime Text console in order to determine the encoding of the file:
view.encoding() // 'Undefined'

delete special characters preceding shebang (M-oM-;M-?#!/bin/bash) [duplicate]

I have a CSV file with special accents and save it in Notepad by selecting UTF-8 encoding. When I read the file using Java, it reads the BOM characters too.
So I want to save this file in UTF-8 format without appending a BOM initially in Notepad.
Otherwise, is there a built-in class in Java that eliminates the BOM characters that present at beginning, when reading the contents in a file?
Use Notepad++ - it is free and much better than Notepad. It will help to save text without a BOM using Encoding → Encode in UTF-8 without BOM: Notepad++ v6 and olders:
Notepad++ v7+:
When I encountered this problem in Java, I didn't find any library to parse these first three bytes (BOM). So my advice:
Use PushbackInputStream(in, 3).
Read the first three bytes
If it's not BOM (EF BB BF), push them back
Process the stream as UTF-8
I just learned from this Stack Overflow post, as #martin-geisler points out, that you can save files without the BOM in Windows Notepad, by selecting ANSI as the encoding.
I'm assuming that for more advanced uses this won't work because the resulting file is probably not the end encoding wished, but actually ANSI; but I tested and confirmed this works to save a very small .php script without BOM using only Notepad.
I learned the long, hard way that Windows' Notepad is not a true editor, although I'd like to point out for others that, despite this, it is misleadingly called up when you type "editor" on newer Windows machines, at least on one of mine.
I am currently using Emacs and other editors to solve this problem.
Use Notepad++ instead. See my personal blog post on it. From within Notepad++, choose the "Encoding" menu, then "Encode in UTF-8 without BOM".
Notepad on Windows 10 version 1903 (May 2019 update) and later versions supports saving to UTF-8 without a BOM. In fact, UTF-8 is the default file format now.
Reference: Windows 10 Notepad is Getting Better UTF-8 Encoding Support
The answer is: Not at all. Notepad can't do that.
In Java you can just skip the first byte in your InputStream and be done.
You might want to try out Notepad2 or Notepad++. Those Notepad replacements have the option for you to choose whether to output BOM.
As for a Java solution, as far as I know, Java does not understand the standard UTF-8. I googled and found Java's UTF-8 and Unicode writing is broken - Use this fix that might be the solution.
We're using the utility BOMStripperInputStream.java to strip the BOM from our input if present.

String unknown Eclipse

I've changed the encoding from Eclipse but all my strings with special characters now are like this "�". The old encoding was the Default (Cp1252), now it is UTF-8. How can I fix the strings with special characters?
Thanks.
Well, imagine you switch your brain to only understand Chinese. Could you read an English text anymore?
You changed the way Eclipse interprets the bits of your sourcecode. So you need to translate the sourcecode from Cp1252 to UTF-8.
I don't know if Eclipse is able to do this, but Notepad++ is.
Open a java-file you want to change the encoding of in Notepad++.
Click on Encoding
Select Convert to UTF-8
Save the file
When you now click on Encoding again, there should be a dot in front of Encode in UTF-8
Edit: Notepad++ recognizes the used encoding, so you can read it there. Copy and Paste from Notepad++ to Eclipse won't work, because you copied the same string Eclipse couldn't read. You have to change the encoding of the string.

Resources