如何使用Visual Studio .NET将具有特定代码页的文本文件转换为UTF-8

A partner recently sent me a RESX (.NET Resource) text file in Hebrew for a project I'm working on. When I opened it, it looked really bad, as seen in the screenshot below.

一个合作伙伴最近向我发送了希伯来语中我正在处理的项目的RESX(.NET资源)文本文件。 当我打开它时,它看上去真的很糟糕,如下面的屏幕截图所示。

I assumed this was a classic ANSI vs. UTF-8 problem, so I tried to do a quick conversion within Notepad2, but that resulted in nonsense East Asian characters from all over:

我以为这是ANSI与UTF-8的经典问题,因此我尝试在Notepad2中进行快速转换,但是这导致了各地的废话东亚字符:

This means that the original file was in fact in ASCII, but just not using an English codepage. I've talked a little about codepages in the Hanselminutes Podcast on Internationalization in the past and regularly point folks to the Joel on Software article on Internationalization.

这意味着原始文件实际上是ASCII的,但只是没有使用英语代码页。 在过去的Hanselminutes播客中,我已经谈过关于国际化的代码页面,并经常指出人们关于国际化乔尔软件文章

In a nutshell, a codepage is a "view" that someone can use to look

简而言之,代码页是某人可以用来查看的“视图”

Ordinarily, I recommend that everyone (including Israelis) use Unicode/UTF-8 to represent their Hebrew characters, however, a lot of folks who write Hebrew use the Windows 1255 codepage for their encoding. (BTW, go here, scroll down, and bask in the glory of this reference site.)

通常,我建议每个人(包括以色列人)都使用Unicode / UTF-8表示希伯来语字符,但是,许多使用希伯来语的人都使用Windows 1255代码页进行编码。 (顺便说一句,请转到此处,向下滚动,并欣赏该参考站点的荣耀。 )

So, how do I convert from one codepage to another, or in my case, from Hebrew 1255 to UTF8?

那么,如何将一个代码页转换为另一代码页,或者从希伯来语1255转换为UTF8?

We start with Visual Studio.NET.

我们从Visual Studio.NET开始。

  • From the File menu, select Open to bring up the dialog. Note that you'll have to select a file before the Open button is un-grayed.

    从文件菜单中,选择打开以打开对话框。 请注意,在打开按钮变为灰色之前,您必须选择一个文件。
  • Select the tiny down-arrow on the right side of the Open button and select "Open With..."

    选择“打开”按钮右侧的小向下箭头,然后选择“打开方式...”
    • -5 points for obscure UI design here

      -5点用于晦涩的UI设计

  • Next, select "Source Code (Text) Editor with Encoding." The With Encoding part is crucial, otherwise the next dialog won't appear.

    接下来,选择“带有编码的源代码(文本)编辑器”。 使用编码部分至关重要,否则下一个对话框将不会出现。

    Next, select "Source Code (Text) Editor with Encoding." The With Encoding part is crucial, otherwise the next dialog won't appear.

    接下来,选择“带有编码的源代码(文本)编辑器”。 使用编码部分至关重要,否则下一个对话框将不会出现。

  • From the Encoding Dialog, select the source document's encoding - in my case, that's Hebrew 1255.

    从“编码”对话框中,选择源文档的编码-在我的情况下为希伯来语1255。
    • -10 points for obscure UI design here.

      -10点用于晦涩的UI设计。

      -10 points for obscure UI design here.

      -10点用于晦涩的UI设计。

  • At this point the document should appear correctly in Visual Studio.NET. Now, reverse the process by selecting File|Save As and clicking the tiny down arrow on the Save button, and selecting both the desired Encoding and Line Endings.

    此时,文档应正确显示在Visual Studio.NET中。 现在,通过选择“文件” |“另存为”,然后单击“保存”按钮上的细小的向下箭头,然后选择所需的“编码”和“行尾”,来逆转该过程。

    At this point the document should appear correctly in Visual Studio.NET. Now, reverse the process by selecting File|Save As and clicking the tiny down arrow on the Save button, and selecting both the desired Encoding and Line Endings.

    此时,文档应正确显示在Visual Studio.NET中。 现在,通过选择“文件” |“另存为”并单击“保存”按钮上的细小的向下箭头,然后选择所需的“编码”和“行尾”来逆转该过程。

Now you've successfully normalized your document to UTF-8, and it should be usable as a RESX file or whatever you like. Here's that same document loaded into Notepad2.

现在,您已经成功将文档标准化为UTF-8,它可以用作RESX文件或任何您喜欢的文件。 这是加载到Notepad2中的同一文档。

And it was Good.

很好。

翻译自: https://www.hanselman.com/blog/how-to-convert-a-text-file-with-a-specific-codepage-to-utf8-using-visual-studio-net

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值