vb.net转换文件编码 vb数据类型转换
vb.net中string 转 unicode 编码
Unicode编码是一个数组,其中每个元素代表一个位码,还有ASCII和UTF8两种编码格式。
我们提供的服务有:成都网站设计、做网站、微信公众号开发、网站优化、网站认证、砀山ssl等。为上千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的砀山网站制作公司
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编码,例如“广东”变成%B9%E3%B6%AB
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解码
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.netmp4视频怎么改编码
打开格式转换
进入软件,然后打开视频格式转换功能。
2/3
导入视频
进入转换功能后,选择一段视频,然后点击下一步。
完美动力怎么剪辑视频-CG行业全能人才孵化基地
值得一看的视频相关信息推荐
完美动力广告
3/3
设置编码格式
视频导入成功后,首先设置目标编码格式,然后点击开始转换即可。
VB 怎么更改TXT编码格式和读取Txt指定字符
VB可以通过CreateObject函数来实现打开UTF-8编码格式文本文件,将它显示于文本框中。并可通过Print # 语句将格式化显示的数据以ANSI格式写入顺序文件中。
CreateObject函数,创建并返回一个对 ActiveX 对象的引用。
Print # 语句,将格式化显示的数据写入顺序文件中。
以下是实现代码:
Private Sub Command1_Click()
Dim ados As Object
Dim str As String
CommonDialog1.FileName = ""
CommonDialog1.Filter = "文本文件(*.txt)|*.txt|"
CommonDialog1.Action = 1
str = CommonDialog1.FileName
Debug.Print str
Set ados = CreateObject("adodb.stream")
With ados
.Charset = "utf-8"
.Type = 2
.Open
.LoadFromFile str
Text1.Text = .ReadText
.Close
End With
Debug.Print Mid(str, 1, Len(str) - 4) "1.txt"
Open Mid(str, 1, Len(str) - 4) "1.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub
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字节数组
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)
Return bytes
End Function
'这里可以类推出好几种。
网站栏目:vb.net转换文件编码 vb数据类型转换
转载源于:http://ybzwz.com/article/doocgpp.html