189 8069 5689

vbnet编码转换 vb转vbnet

vb.net怎么把汉字转换为GB2312编码,例如“广东”变成%B9%E3%B6%AB

GB2312是GBK编码的子集,使用GBK编码函数即可

创新互联专注于企业成都营销网站建设、网站重做改版、南溪网站定制设计、自适应品牌网站建设、html5成都做商城网站、集团公司官网建设、成都外贸网站建设公司、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为南溪等各大城市提供网站开发制作服务。

'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解码

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中string 转 unicode 编码

Unicode编码是一个数组,其中每个元素代表一个位码,还有ASCII和UTF8两种编码格式。

Unicode:

Dim bytes() As Byte() = System.Text.Encoding.Unicode.GetBytes("字符串")

ASCII:

Dim bytes() As Byte() = System.Text.Encoding.ASCII.GetBytes("字符串")

UTF8:

Dim bytes() As Byte() = System.Text.Encoding.UTF8.GetBytes("字符串")

vb.net 如何将编码GB2312转成UTF8

Imports System.Text

Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()

Dim bytes() As Byte

bytes = Encoding.UTF8.GetBytes(strData)

Return bytes

End Function

说明:strData参数是GB2312字符串,函数返回UTF8字节数组


当前题目:vbnet编码转换 vb转vbnet
网址分享:http://cdxtjz.cn/article/dojigsc.html

其他资讯