本来以为只有非英语国家的程序被英语国际的人看的时候会有代码页问题,不过,还是发现,英语国家的人,也很喜欢使用一些不属于 ASCII 的特殊字符,结果造成那些代码被非英语国家的人使用的时候,也很麻烦。
Visual Studio 缺省使用当前 Windows 代码页保存文件,实在是个不可思议的决定,不过,既然发生了,还是要解决。上网查了一下,奇怪的是,很多人问到这个问题,却没有发现提供解决方法。
确实,在 Visual Studio 的选项里翻弄了半天,还是没有发现可以设置缺省代码页的地方。
最后,在“文件”菜单发现“高级保存选项”,可以设置代码页,再测试一下,这个设置对于新建文件也有效。看来它就是缺省代码页了,只是不知道为什么不放在“选项”对话框中。
另外,还有一个问题,就是现有程序怎么办,没有发现现成的工具,就自己写了一个,代码很简单,一个 WinForm 窗口,有一个叫 FileCollector 的 ListBox,一个叫 Run 的按钮,一个叫 FileCount 的 Label,然后是代码:
// Recode 1.0
// http://llf.hanzify.org
// http://llf.iteye.com
// 作者:梁利锋
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace Recode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void FileCollector_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Link;
}
private void FileCollector_DragDrop(object sender, DragEventArgs e)
{
var list = (Array) e.Data.GetData(DataFormats.FileDrop);
if (list != null && list.Length > 0)
{
FileCollector.Items.Clear();
foreach (object f in list)
{
string s = f.ToString();
if (File.Exists(s))
{
FileCollector.Items.Add(s);
}
}
}
FileCount.Text = FileCollector.Items.Count.ToString();
}
private void Run_Click(object sender, EventArgs e)
{
if (FileCollector.Items.Count > 0)
{
foreach (string name in FileCollector.Items)
{
RecodeOneFile(name);
}
MessageBox.Show("done!");
}
else
{
MessageBox.Show("Please drag and drop some files to the list box first.");
}
}
private static void RecodeOneFile(string name)
{
string content;
using (var sr = new StreamReader(name, Encoding.GetEncoding(1252))) // 英文代码页
{
content = sr.ReadToEnd();
}
using (var sw = new StreamWriter(name, false, Encoding.UTF8))
{
sw.Write(content);
}
}
}
}
我个人比较喜欢带签名的 UTF-8 格式,对于源文件的代码页,可以查一下这个
代码页介绍的文章。
分享到:
相关推荐
为了保持代码的整洁和可读性,Visual Studio.NET提供了代码整理功能,只需选择“编辑”菜单下的“整理代码”选项即可快速优化代码格式。在实际编程过程中,熟练掌握这些快捷键和特性,能显著提高开发速度。 #### ...
1、在使用Visual Studio .NET时,除直接或非引用的对象外,不要使用缺省的名字。 .NET带来的好处之一是所有的源代码和配置文件都是纯文本文件,能够使用Notepad或WordPad等任意的文本编辑器进行编辑。如果不...
1. **Visual Studio .NET**(版本2002或2003均可) 2. **Adaptive Server Anywhere 9.0** 数据库 3. **Microsoft IIS** (Internet Information Services) #### 三、环境配置 ##### 3.1 启动Microsoft IIS web服务器...
因此,在进行现代软件开发时,考虑使用更新的IDE版本(如Visual Studio 2019/2022等)可能会更加高效。 通过上述步骤,开发者可以在VC6.0环境下成功配置并使用WinPcap进行高效的网络数据捕获和分析工作。
此外,使用Visual Studio的调试工具也是提高开发效率的关键。 8. **页面生命周期理解**: 理解ASP.NET页面生命周期,包括初始化、加载、验证、呈现和卸载等阶段,有助于编写正确的事件处理程序,并确保在正确的...
18.2 在 C #代码中调用 C++和 VB 编写的组件 .240 18.3 版 本 控 制 .249 18.4 代 码 优 化 .252 18.5 小 结 .254 第五部分 附 录 .255 附录 A 关 键 字.255 附录 B 错 误 码.256 附录 C .Net 名字空间...
1. **打开Visual Studio**,在解决方案资源管理器中选中项目。 2. 在工具箱中右键点击,选择“选择项”。 3. 在弹出的对话框中,选择“浏览”,定位到包含`TeeChart.dll`的文件夹并选中该文件。 4. 完成后,工具箱中...
Supports building detours with Visual Studio 2005, Visual Studio .NET 2003, Visual Studio .NET (VC8), and Visual Studio (VC7). Detours 2.1 comes in two editions: Detours Express 2.1 is available for ...