vb.net怎么把汉字转换为GB2312编码,例如“广东”变成广东GB2312是GBK编码的子集,使用GBK编码函数即可
'GBK编码(结果以百分号%进行分隔)
Public Function GBKEncode(ByVal sInput As String) As String
Dim ret_GBKEncode As String = ""
Dim i As Integer
Dim startIndex As Integer = 0
Dim endIndex As Integer
Dim x() As Byte = System.Text.Encoding.Default.GetBytes(sInput) '字符以及字符串在vb2008中都是以unicode编码存储的
endIndex = x.Length - 1
For i = startIndex To endIndex
ret_GBKEncode = "%"Hex(x(i))
Next
Return ret_GBKEncode
End Function
'GBK解码
【vbnet编码转换 vba编码转换】Public Function GBKDecode(ByVal sInput As String) As String
sInput = sInput.Replace("%", "")
Dim ret_GBKDecode As String = ""
Dim sLen As Integer = sInput.Length
Dim n As Integer = sLen \ 2
Dim sBytes(0 To n - 1) As Byte
'转化为字节码
For i As Integer = 1 To n
sBytes(i - 1) = CByte("H"sInput.Substring(2 * i - 2, 2))
Next
'将字节码转化为字符串
ret_GBKDecode = System.Text.Encoding.Default.GetString(sBytes)
Return ret_GBKDecode
End Function
vb.net 如何吧字符穿转换成键盘码(1)在Form1上布置一个Label,用来显示键盘码
(2)窗体代码如下
Imports System.Windows.Forms
Imports System.IO
Imports System.Net
Imports System.Windows.Forms
Imports System.IO
Imports System.Net
Public Class Form1
Private Sub Form1_Load(sender As Object,
e As EventArgs) Handles MyBase.Load
KeyPreview = True
End Sub
Private Sub Form1_KeyDown(sender As Object,
e As KeyEventArgs) Handles MyBase.KeyDown
Label1.Text = e.KeyValue
End Sub
End Class
按键盘上的键,Label1将显示对应键的键盘码
vb.net 如何将编码GB2312转成UTF8Imports System.Text
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Dim bytes() As Byte
bytes = Encoding.UTF8.GetBytes(strData)
Return bytes
End Function
说明vbnet编码转换:strData参数是GB2312字符串vbnet编码转换,函数返回UTF8字节数组
关于vbnet编码转换和vba编码转换的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
推荐阅读
- 网站开发小程序开发app开发,网站开发小程序开发app开发方案
- zblog怎么设置免责声明,zblog使用教程
- java代码质量审查,java代码评审工具
- b站的征战直播在哪,b站直播比赛
- c语言中creat函数 c语言create函数在哪个头文件
- oracle表的日期,oracle中的日期函数
- u盘存视频用什么牌子,带视频的u盘
- mysql数据库的恢复和备份,mysql数据库的恢复和备份是什么
- php指定一天的数据 php定时执行每天执行一次