vb中如何将字符串转换为UTF-8编码?
比如字符串:“微软计算机”转换为【%e5%be%ae%e8%bd%af%e8%ae%a1%e7%ae%97%e6%9c%ba】请教了!...
比如字符串:“微软计算机” 转换为 【%e5%be%ae%e8%bd%af%e8%ae%a1%e7%ae%97%e6%9c%ba】
请教了! 展开
请教了! 展开
展开全部
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
Private Const CP_ACP = 0 ' default to ANSI code page
Private Const CP_UTF8 = 65001 ' default to UTF-8 code page
Private Sub Command1_Click()
Dim s As String, a() As Byte
s = Text1.Text
a = EncodeToBytes(s)
For i = 0 To UBound(a)
Text2.Text = Text2.Text & Hex(a(i)) & " "
Next
End Sub
Public Function EncodeToBytes(ByVal sData As String) As Byte()
Dim aRetn() As Byte, nSize As Long
nSize = WideCharToMultiByte(CP_UTF8, 0, StrPtr(sData), -1, 0, 0, 0, 0)
ReDim aRetn(0 To nSize - 1) As Byte
WideCharToMultiByte CP_UTF8, 0, StrPtr(sData), -1, VarPtr(aRetn(0)), nSize, 0, 0
EncodeToBytes = aRetn
End Function
追问
谢谢哈!楼下完美帮我解决了!
展开全部
dim e as object
Set e=CreateObject("MSScriptControl.ScriptControl")
e.Language = "javascript"
dim d as stringd= e.Eval("encodeURI('微软计算机')") '运行javascript脚本的函数
MsgBox d
MsgBox e.Eval("decodeURI('" & d & "')")
追问
追加悬赏 50,共计 150~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
vb里汉字就是一个字符
MsgBox (Len("汉字"))这句显示为2
MsgBox (Len("汉字"))这句显示为2
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询