儿童绘本电子版:如何将UTF-8转换为ASCI?

来源:百度文库 编辑:神马品牌网 时间:2024/04/20 14:36:16
如何将UTF-8转换为ASCI?
或用软件或VB/VBS/ASP代码。急用阿
说本质吧
在是一个脚本读取网页,然后分析,但是中文是UTF-8编码,VBS不能识别,怎么办?
就是将UTF-8编码转换成ASCI,用代码转换,VB/VBScript语言,VB不能使用API。
整个程序是由记事本编写的脚本。
到1月13日还没有可行答案

vb代码么,WideCharToMultiByte、MultiByteToWideChar这两个API

ASP.net 中则可以简单的使用下面代码:

Encoding gb2312 = Encoding.GetEncoding("gb2312");
Response.ContentEncoding = gb2312;

参见这篇文章
http://blog.joycode.com/ghj/archive/2005/05/19/51584.aspx

我说的已经够清楚了,如果想用程序转,.net封装了API,不用.net的话只能用API了

记事本就可以呀
另存为下面有个编码

可以这样做
用C#编写一个简单的类似的小程序.把下面的代码另存为
changeCode.cs .然后在命令提示符下敲入:csc changeCode.cs.然后运行changeCode.exe.读取你要变得文件。然后写入就行了。你试试。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.IO;
using System.Text;

namespace TextReader
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(424, 208);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(56, 224);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(168, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 224);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 21);
this.label1.TabIndex = 2;
this.label1.Text = "文件名:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(232, 224);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "读文件";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(320, 224);
this.button2.Name = "button2";
this.button2.TabIndex = 4;
this.button2.Text = "写文件";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(424, 262);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//public TextReader r;
private StreamReader r;
//public TextWriter w;
private StreamWriter w;

private void button1_Click(object sender, System.EventArgs e)
{
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
textBox1.Text=openFileDialog1.FileName;
r=new StreamReader(openFileDialog1.FileName,System.Text.Encoding.UTF8);
richTextBox1.Text=r.ReadToEnd();
r.Close();
}

}

private void button2_Click(object sender, System.EventArgs e)
{
if(saveFileDialog1.ShowDialog()==DialogResult.OK)
{
textBox1.Text=saveFileDialog1.FileName;
w=new StreamWriter(saveFileDialog1.FileName,false,System.Text.Encoding.ASCII);
w.Write(richTextBox1.Text);
w.Flush();
w.Close();
}

}

}
}

把vbs脚本另存为utf8格式即可