vb.net互换字节 vbnet byte转成string

gb2312>unicode>utf8, 以及逆转的方法'>VB.net 字符转换问题 字符(汉字、数字、字母、符号)>gb2312>unicode>utf8,以及逆转的方法字符编码转换吗?
1.字符与gb2312(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
2.Unicode字符串为UTF-8
Imports System.Text
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Dim bytes() As Byte
bytes = Encoding.UTF8.GetBytes(strData)
【vb.net互换字节 vbnet byte转成string】Return bytes
End Function
'这里可以类推出好几种 。
刚入手VB.NET不知道怎么将数字转换成字节数组Private Function Conver_Hex(ByVal L As Long) As Array
Dim str_L As String = Hex(L)
If str_L.Length \ 20 Then
str_L = "0"str_L
End If
Dim byt(str_L.Length / 2 - 1) As Byte
For i = 0 To str_L.Length / 2 - 1
byt(i) = Convert.ToByte(str_L.Substring(2 * i, 2), 16)
Next
Return byt
End Function
'下面是调用代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim L As Double = 123456
Dim byt() As Byte = Conver_Hex(L)
End Sub
vb.net 如何将十六进制字符串转换为十六进制变量numHex =Integer.Parse(strHex, Globalization.NumberStyles.AllowHexSpecifier)

numHex = Integer. Parse("H"strHex)
VB.net 如何将bytes()字节数组转换到short型数组?for一下,将bytes中的字节转为short , for中就可以将要使用的short进行处理了
如何将VB.NET字符串转换成字节数组1、字节数组转换为字符串
byte[] byBuffer = new byte[20];
String strRead = new String(byBuffer);
strRead = String.copyValueOf(strRead.toCharArray(), 0, byBuffer.length]);
2、字符串转换成字节数组
byte[] byBuffer = new byte[200];
String strInput=abcdefg;
byBuffer= strInput.getBytes();
注意vb.net互换字节:如果字符串里面含有中文vb.net互换字节,要特别注意,在android系统下,默认是UTF8编码 , 一个中文字符相当于3个字节,只有gb2312下一个中文相当于2字节 。这种情况下可采取以下办法:
如何将VB.NET 字符串转换成字节数组ToCharArray()
例如:str="asdfafafafaf"
str.toCharArray就是一个Char()数组了 。
vb.net互换字节的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet byte转成string、vb.net互换字节的信息别忘了在本站进行查找喔 。

    推荐阅读