vb.net编码解码 vbnet代码

是用VB.NET自带的 BASE64 编码 。然后用java的Base64能解码吗...可能不行 。
关键在于Base64 的码表不同 , 造成很多专用领域的base64算法 。
比如 , url中“/”有特殊含义,所依,在浏览器里一般都用“-、*”来替换“+、/”两个符号,造成不同的base64 变种 。
Quoted-Printable编码的邮件解码,vb.net代码怎么写,谢谢Dim Lines = System.IO.File.ReadAllLines("D:\zhege\qp.txt")
'邮件源代码应该是分行读?。婊坏粽飧鍪榫托?。for代码段符合流的读取行方法(readline) 。
Dim codeBuilder As New System.Text.StringBuilder
For Each code As String In Lines
code = code.Replace("==", "=")
If code.EndsWith("=") Then
code = code.Substring(0, code.Count - 1)
codeBuilder.Append(code)
ElseIf code"" Then
codeBuilder.AppendLine(code)
End If
Next
Dim reg As New System.Text.RegularExpressions.Regex("(=(\d|[A-F]){2}){1,}")
Dim match As System.Text.RegularExpressions.Match = Nothing
While reg.IsMatch(codeBuilder.ToString)
match = reg.Match(codeBuilder.ToString)
Dim Bytes As New List(Of Byte)
For Each cMatch As String In Replace(match.Value, "=", "", 1, 1).Split("="c)
Bytes.Add(CByte("h"cMatch))
Next
codeBuilder = codeBuilder.Replace(match.Value, System.Text.Encoding.Default.GetString(Bytes.ToArray))
End While
MsgBox(codeBuilder.ToString)
我只测试了一段qp代码,可能有误 。如果qp不是Default编码,结果可能是乱码,需要注意
求教vb.net utf-8 解码Public Function GBKDecode(ByVal sInput As String) As String
sInput = sInput.Replace("%", "")
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.UTF8.GetString(sBytes)
Return ret_GBKDecode
End Function
'上面是函数,调用方法
MsgBox(GBKDecode(":%E9%80%81%E8%BE%BE%E6%97%A5%E6%9C%9F%20%E9%80%81%E8%BE%BE%E6%97%B6%E9%97%B4"))
vb.net怎么把汉字转换为GB2312编码,例如“广东”变成%B9%E3%B6%ABGB2312是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解码
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
【vb.net编码解码 vbnet代码】End Function
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
说明:strData参数是GB2312字符串 , 函数返回UTF8字节数组

推荐阅读