急求 在cobol中 ascii和unicode的转换方法 100
在线等啊,需要ascii和unicode的相互转换方法语言是cobol(v3r4)好的可以追分。谢谢哎呀,你简单给我说下算法也比给我vb代码好啊,这我完全看不明白啊。。。...
在线等啊, 需要ascii 和 unicode的相互转换方法
语言是 cobol(v3r4)
好的可以追分。
谢谢
哎呀, 你简单给我说下算法也比给我vb代码好啊,这我完全看不明白啊。。。。 展开
语言是 cobol(v3r4)
好的可以追分。
谢谢
哎呀, 你简单给我说下算法也比给我vb代码好啊,这我完全看不明白啊。。。。 展开
1个回答
展开全部
VB Unicode 转 ASCII
Public Function Unicode2AscII(ByVal s As String)
On Error Resume Next
Dim i As Integer
Dim r As String
For i = 1 To Len(s) Step 4
r = r + ChrB("&H" & Mid(s, i + 2, 2)) & ChrB("&H" & Mid(s, i, 2))
Next
Unicode2AscII = r
End Function
'使用示例,添加一个CommandButton,名为Command1
'两个TextBox,名称分别为Text1和Text2,复制以下代码运行即可
Private Sub Form_Load()
Text1.Text = "mms%3a%2f%2fserver4.aeeboo.com%2faeeboowang%2fAeebooUploadFiles90001_100000%2fherewn%2f%u6211%u7684%u5973%u795e(Q%u7248)26.wmv%3fpxd%3d1167565477"
End Sub
Private Sub Command1_Click()
Dim s As String, k As Long, s2 As String
k = 1: s2 = Text1.Text
Do Until InStrRev(s2, "%") = 0
k = InStr(k, s2, "%")
s = Mid(s2, k + 1, 5)
If Left(s, 1) = "u" Then
s2 = Replace(s2, "%" & s, Unicode2AscII(Right(s, 4)))
Else
s2 = Replace(s2, "%" & Left(s, 2), Chr$("&H" & Left(s, 2)))
End If
Loop
Text2.Text = s2
End Sub
'下面操作将把Asscii格式的文件kk.txt转换为以Unicode格式的文件nn.txt
Private Sub Command1_Click()
Dim FSO As New FileSystemObject
Dim f As TextStream
Dim s As String
Set f = FSO.OpenTextFile("C:\Documents and Settings\xtgl\桌面\kk.txt")
s = f.ReadAll
f.Close
s = StrConv(s, vbUnicode)
Set f = FSO.CreateTextFile("C:\Documents and Settings\xtgl\桌面\nn.txt")
f.Write s
f.Close
Debug.Print "ok"
End Sub
Public 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
Public Const CP_UTF8 = 65001
Public Function UTF8_Decode(bUTF8() As Byte) As String
Dim lRet As Long
Dim lLen As Long
Dim lBufferSize As Long
Dim sBuffer As String
Dim bBuffer() As Byte
lLen = UBound(bUTF8) + 1
If lLen = 0 Then Exit Function
lBufferSize = lLen * 2
sBuffer = String$(lBufferSize, Chr(0))
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(bUTF8(0)), lLen, StrPtr(sBuffer), lBufferSize)
If lRet <> 0 Then
sBuffer = Left(sBuffer, lRet)
End If
UTF8_Decode = sBuffer
End Function
Public Function Unicode2AscII(ByVal s As String)
On Error Resume Next
Dim i As Integer
Dim r As String
For i = 1 To Len(s) Step 4
r = r + ChrB("&H" & Mid(s, i + 2, 2)) & ChrB("&H" & Mid(s, i, 2))
Next
Unicode2AscII = r
End Function
'使用示例,添加一个CommandButton,名为Command1
'两个TextBox,名称分别为Text1和Text2,复制以下代码运行即可
Private Sub Form_Load()
Text1.Text = "mms%3a%2f%2fserver4.aeeboo.com%2faeeboowang%2fAeebooUploadFiles90001_100000%2fherewn%2f%u6211%u7684%u5973%u795e(Q%u7248)26.wmv%3fpxd%3d1167565477"
End Sub
Private Sub Command1_Click()
Dim s As String, k As Long, s2 As String
k = 1: s2 = Text1.Text
Do Until InStrRev(s2, "%") = 0
k = InStr(k, s2, "%")
s = Mid(s2, k + 1, 5)
If Left(s, 1) = "u" Then
s2 = Replace(s2, "%" & s, Unicode2AscII(Right(s, 4)))
Else
s2 = Replace(s2, "%" & Left(s, 2), Chr$("&H" & Left(s, 2)))
End If
Loop
Text2.Text = s2
End Sub
'下面操作将把Asscii格式的文件kk.txt转换为以Unicode格式的文件nn.txt
Private Sub Command1_Click()
Dim FSO As New FileSystemObject
Dim f As TextStream
Dim s As String
Set f = FSO.OpenTextFile("C:\Documents and Settings\xtgl\桌面\kk.txt")
s = f.ReadAll
f.Close
s = StrConv(s, vbUnicode)
Set f = FSO.CreateTextFile("C:\Documents and Settings\xtgl\桌面\nn.txt")
f.Write s
f.Close
Debug.Print "ok"
End Sub
Public 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
Public Const CP_UTF8 = 65001
Public Function UTF8_Decode(bUTF8() As Byte) As String
Dim lRet As Long
Dim lLen As Long
Dim lBufferSize As Long
Dim sBuffer As String
Dim bBuffer() As Byte
lLen = UBound(bUTF8) + 1
If lLen = 0 Then Exit Function
lBufferSize = lLen * 2
sBuffer = String$(lBufferSize, Chr(0))
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(bUTF8(0)), lLen, StrPtr(sBuffer), lBufferSize)
If lRet <> 0 Then
sBuffer = Left(sBuffer, lRet)
End If
UTF8_Decode = sBuffer
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询