这是一篇前N天的文章了!那天由于断网了!突然想起前段有个朋友问过关于BIG5跟GB2312编码转换的问题,这个在CSDN上搜索的。都没什么真正解决的!然后我就亲身测试了下,把结果代码与大家分享下哄!
讲讲思路,其实代码就是先把BIG5转GBK,然后再把GBK转成GB2312,反之亦然啊!请见代码如下:
讲讲思路,其实代码就是先把BIG5转GBK,然后再把GBK转成GB2312,反之亦然啊!请见代码如下:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm13.aspx.vb" Inherits="WebApplication12.WebForm13" validateRequest="false"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm13</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:textbox id="TextBox1" style="Z-INDEX: 101; LEFT: 17px; POSITION: absolute; TOP: 11px" runat="server"
Width="503px" Height="176px" TextMode="MultiLine"></asp:textbox><asp:button id="Button1" style="Z-INDEX: 102; LEFT: 90px; POSITION: absolute; TOP: 368px" runat="server"
Width="113px" Height="34px" Text="gb2312转big5"></asp:button><asp:textbox id="TextBox2" style="Z-INDEX: 103; LEFT: 17px; POSITION: absolute; TOP: 193px" runat="server"
Width="504px" Height="163px" TextMode="MultiLine"></asp:textbox><asp:button id="Button2" style="Z-INDEX: 104; LEFT: 312px; POSITION: absolute; TOP: 366px" runat="server"
Width="110px" Height="35px" Text="big5转gb2312"></asp:button></FONT></form>
</body>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm13</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:textbox id="TextBox1" style="Z-INDEX: 101; LEFT: 17px; POSITION: absolute; TOP: 11px" runat="server"
Width="503px" Height="176px" TextMode="MultiLine"></asp:textbox><asp:button id="Button1" style="Z-INDEX: 102; LEFT: 90px; POSITION: absolute; TOP: 368px" runat="server"
Width="113px" Height="34px" Text="gb2312转big5"></asp:button><asp:textbox id="TextBox2" style="Z-INDEX: 103; LEFT: 17px; POSITION: absolute; TOP: 193px" runat="server"
Width="504px" Height="163px" TextMode="MultiLine"></asp:textbox><asp:button id="Button2" style="Z-INDEX: 104; LEFT: 312px; POSITION: absolute; TOP: 366px" runat="server"
Width="110px" Height="35px" Text="big5转gb2312"></asp:button></FONT></form>
</body>
</HTML>
Imports System
Imports System.Net
Imports System.io
Imports System.text
Public Class WebForm13
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
''big5转gb2312
Dim str As String = TextBox1.Text
Dim gb2312 As String = Encoding.Default.GetString(Encoding.Convert(Encoding.GetEncoding(950), Encoding.GetEncoding(936), Encoding.Default.GetBytes(str)))
TextBox2.Text = StrConv(gb2312, VbStrConv.SimplifiedChinese)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
''gb2312转big5
Dim str As String = TextBox1.Text
str = StrConv(str, VbStrConv.TraditionalChinese)
TextBox2.Text = Encoding.Default.GetString(Encoding.Convert(Encoding.GetEncoding(936), Encoding.GetEncoding(950), Encoding.Default.GetBytes(str)))
End Sub
End Class
Imports System.Net
Imports System.io
Imports System.text
Public Class WebForm13
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
''big5转gb2312
Dim str As String = TextBox1.Text
Dim gb2312 As String = Encoding.Default.GetString(Encoding.Convert(Encoding.GetEncoding(950), Encoding.GetEncoding(936), Encoding.Default.GetBytes(str)))
TextBox2.Text = StrConv(gb2312, VbStrConv.SimplifiedChinese)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
''gb2312转big5
Dim str As String = TextBox1.Text
str = StrConv(str, VbStrConv.TraditionalChinese)
TextBox2.Text = Encoding.Default.GetString(Encoding.Convert(Encoding.GetEncoding(936), Encoding.GetEncoding(950), Encoding.Default.GetBytes(str)))
End Sub
End Class