ANSI vs SHIFT JIS vs UTF-8 in C #

I’ve been trying to understand the difference for quite some time. The problem with the ANSI encoded file has Japanese characters, such as: ­‚È‚­‚Æ‚à1‚‚ÌINCREMENTs‚ª•K—v‚Å‚·.It is equivalent to shift-jis 少なくとも1つのINCREMENT行が必要です., which is expected to be in Japanese.

I need to display these characters after reading from a file (in ANSI) on a web page. There are other files in UTF-8 that display characters without seeing this. I find it hard to understand what the difference is and how to change the encoding to do the right thing here. I use C # to read this file and display it, I also need to write the line back to the file if it has been modified on the Internet. Any encoding and decoding schemes here?

+5
source share
1 answer

As for code pages, “ANSI” (and Encoding.Defaultin .NET) basically just means “non-Unicode code page used by this system” - exactly which code page that exists depends on how the system is the Western European system is most likely Windows-1252.

For the system where this text comes from, then “ANSI” will mean Shift-JIS, so if your system does not have the same code page, you need to tell your code to read the text as Shift-JIS.

, StreamReader, , Encoding, Shift-JIS Encoding.GetEncoding("shift_jis") Encoding.GetEncoding(932) StreamReader.

+6

All Articles