求一个函数:UTF8转换为GB2312 (在线等待,马上给分)

qiri07 2003-07-11 11:46:52
急用~~~
...全文
64 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xixigongzhu 2003-07-18
  • 打赏
  • 举报
回复
用两种不同的编码进行编码和解码,除非这两种编码是兼容的,否则得到的结果肯定是乱码。
如果你要实现这种功能的话,必须先找到两种编码的特点和对应关系,然后根据这个进行映相(mapping)。
qiri07 2003-07-18
  • 打赏
  • 举报
回复
谢谢楼上 我先看看~~~
Montaque 2003-07-17
  • 打赏
  • 举报
回复
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'写一个utf的文件。
Dim fs As New System.IO.FileStream("d:\a.txt", IO.FileMode.OpenOrCreate)
Dim sw As New System.IO.StreamWriter(fs, System.Text.Encoding.UTF8)
sw.Write("Hello,中国")
sw.Close()
fs.Close()

End Sub

'utf8编码的文件改为gb
Private Sub utf2Gb2312(ByVal FileName As String)
Dim fs As New System.IO.FileStream(FileName, IO.FileMode.Open)
Dim sr As New System.IO.StreamReader(fs, System.Text.Encoding.UTF8)
Dim sTemp As String = sr.ReadToEnd
sr.Close()
fs.Close()
System.IO.File.Delete(FileName)
Dim sw As New System.IO.StreamWriter(New System.IO.FileStream(FileName, IO.FileMode.OpenOrCreate), System.Text.Encoding.GetEncoding("gb2312"))
sw.Write(sTemp)
sw.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
utf2Gb2312("d:\a.txt")
End Sub
qiri07 2003-07-13
  • 打赏
  • 举报
回复
..
qiri07 2003-07-11
  • 打赏
  • 举报
回复
System.Text.UTF8Encoding
可惜我不会用。。。。
孟子E章 2003-07-11
  • 打赏
  • 举报
回复
Encoding 类
qiri07 2003-07-11
  • 打赏
  • 举报
回复
.....等 高手来。。。
qiri07 2003-07-11
  • 打赏
  • 举报
回复
解决者,分 全部给他
qiri07 2003-07-11
  • 打赏
  • 举报
回复
。。。怎么用?
flers 2003-07-11
  • 打赏
  • 举报
回复
mystring, System.Text.Encoding.GetEncoding("GB2312")
qiri07 2003-07-11
  • 打赏
  • 举报
回复
..
qiri07 2003-07-11
  • 打赏
  • 举报
回复
Dim msgs as string
Dim utf8 As New UTF8Encoding()
Dim unicodeString As String =msgs
Dim encodedBytes As Byte() = utf8.GetBytes(unicodeString)
Dim decodedString As String = utf8.GetString(encodedBytes)
msgs=decodedString

这样,,,好想也不起作用。。。
qiri07 2003-07-11
  • 打赏
  • 举报
回复
UTF8转换为GB2312
拿棵草 2003-07-11
  • 打赏
  • 举报
回复
对,System.Text.UTF8Encoding ,看一下MSDN,里面说的很详细的。

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧