快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

vbnet改变字符集 vbnet 字典

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

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

成都创新互联公司沟通电话:028-86922220,为您提供成都网站建设网页设计及定制高端网站建设服务,成都创新互联公司网页制作领域10多年,包括成都卫生间隔断等多个行业拥有多年建站经验,选择成都创新互联公司,为企业锦上添花。

'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 如何将编码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字节数组

VB.net 以下代码,在取中文文件名时出乱码,怎么办?请教.

没有指定字符集,根据页面的设置,可以设置字符集为UTF-8或GB2312

vb.Net对文件指定字符串的修改

文本框 TextBox1

上一条 Button1

下一条 Button2

修改 Button3

Imports System.IO

Public Class Form1

Dim currIndex As Integer = 0

Dim s2 As List(Of String) = New List(Of String)

Dim s As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

s = File.ReadAllText(Application.StartupPath  "\txt.txt")

Dim s1 As String() = s.Split("@")

For i As Integer = 0 To s1.Length - 1

If s1(i).Trim()  "" Then

s2.Add("@"  s1(i))

End If

Next

TextBox1.Text = s2(0)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

currIndex = currIndex + 1

If currIndex  s2.Count - 1 Then

MsgBox("已经是最后条了")

Return

End If

TextBox1.Text = s2(currIndex)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

currIndex = currIndex - 1

If currIndex  0 Then

MsgBox("已经是第一条了")

Return

End If

TextBox1.Text = s2(currIndex)

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

s2(currIndex) = TextBox1.Text

s = ""

For i As Integer = 0 To s2.Count - 1

s = s2(i)

Next

File.WriteAllText(Application.StartupPath  "\txt.txt", s)

End Sub

End Class

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

'这里可以类推出好几种。


当前文章:vbnet改变字符集 vbnet 字典
转载注明:http://6mz.cn/article/hpeejg.html

其他资讯