How can I transform string to UTF-8 in C#?

As you know the string is coming in as Encoding.Default you could simply use: byte[] bytes = Encoding.Default.GetBytes(myString); myString = Encoding.UTF8.GetString(bytes); Another thing you may have to remember: If you are using Console.WriteLine to output some strings, then you should also write Console.OutputEncoding = System.Text.Encoding.UTF8;!!! Or all utf8 strings will be outputed as gbk…

What is the difference between encode/decode?

The decode method of unicode strings really doesn’t have any applications at all (unless you have some non-text data in a unicode string for some reason — see below). It is mainly there for historical reasons, i think. In Python 3 it is completely gone. unicode().decode() will perform an implicit encoding of s using the … Read more

Change the encoding of a file in Visual Studio Code

So here’s how to do that: In the bottom bar of VSCode, you’ll see the label UTF-8. Click it. A popup opens. Click Save with encoding. You can now pick a new encoding for that file. Alternatively, you can change the setting globally in Workspace/User settings using the setting “files.encoding”: “utf8”. If using the graphical … Read more

Convert Unicode to ASCII without errors in Python

>>> u’aあä’.encode(‘ascii’, ‘ignore’) ‘a’ Decode the string you get back, using either the charset in the the appropriate meta tag in the response or in the Content-Type header, then encode. The method encode(encoding, errors) accepts custom handlers for errors. The default values, besides ignore, are: >>> u’aあä’.encode(‘ascii’, ‘replace’) b’a??’ >>> u’aあä’.encode(‘ascii’, ‘xmlcharrefreplace’) b’aあä’ >>> u’aあä’.encode(‘ascii’, … Read more

PHP DOMDocument loadHTML not encoding UTF-8 correctly

DOMDocument::loadHTML will treat your string as being in ISO-8859-1 (the HTTP/1.1 default character set) unless you tell it otherwise. This results in UTF-8 strings being interpreted incorrectly. If your string doesn’t contain an XML encoding declaration, you can prepend one to cause the string to be treated as UTF-8: $profile=”<p>イリノイ州シカゴにて、アイルランド系の家庭に、9</p>”; $dom = new DOMDocument(); $dom->loadHTML(‘<?xml … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)