ANSI vs SHIFT JIS vs UTF-8在c#中 [英] ANSI vs SHIFT JIS vs UTF-8 in c#

查看:306
本文介绍了ANSI vs SHIFT JIS vs UTF-8在c#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一段时间想找出两者之间的区别了。问题在于使用ANSI编码的文件具有日语字符,例如:,È‚‚Æ‚à1‚‚ÌINCREMENTs‚ª•K-v‚Å,·。相当于shift-jis的是少なくとも1つのINCREMENT行が必要です。可能是日文。

I have been trying to figure the difference for quite sometime now. The issue is with a file that is in ANSI encoding has japanese characters like: ­‚È‚­‚Æ‚à1‚‚ÌINCREMENTs‚ª•K—v‚Å‚·. It equivalent in shift-jis is 少なくとも1つのINCREMENT行が必要です. which is expected to be in japanese.

从网页上的文件(ANSI中)读取后,我需要显示这些字符。 UTF-8中还有一些其他文件显示的字符不正确。我发现很难找出有什么区别,以及如何更改编码以执行正确的操作。.
我使用c#读取此文件并显示它,如果需要,我还需要将字符串写回到文件中在网络上对其进行了修改。

I need to display these characters after reading from file(in ANSI) on a webpage. There are some other files in UTF-8 displaying characters right not seeing this. I am finding it difficult to figure out whats the difference and how do I change encoding to do right things here.. I use c# for reading this file and displaying it, I also need to write the string back into file if its modified on web. Any encoding and decoding schemas here?

推荐答案

就代码页而言, ANSI(和 Encoding.Default )基本上仅表示此系统使用的非Unicode代码页-确切地说,哪个代码页取决于系统的配置方式,但取决于西欧系统,很可能是Windows-1252。

As far as code pages are concerned, "ANSI" (and Encoding.Default in .NET) basically just means "the non-Unicode codepage used by this system" - exactly what codepage that is, depends on how the system is configured, but on a Western European system, it's likely to be Windows-1252.

对于该文本所来自的系统, ANSI似乎表示Shift-JIS-因此,除非您的系统具有

For the system where that text comes from, then "ANSI" would appear to mean Shift-JIS - so unless your system has the same code page, you'll need to tell your code to read the text as Shift-JIS.

假设您正在读取带有

Assuming you're reading the file with a StreamReader, there are various constructors that take an Encoding, so just grab a Shift-JIS encoding with Encoding.GetEncoding("shift_jis") or Encoding.GetEncoding(932) and use it to construct your StreamReader.

这篇关于ANSI vs SHIFT JIS vs UTF-8在c#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆