'看看我写的 URL 编码和解码程序
Public Function EncodeString(StringX As String) As String
Dim i As Long
Dim j As Long
Dim sByte() As Byte
For i = 0 To VBA.Len(VBA.Trim(StringX)) - 1
    If (VBA.Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("0") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("9")) Or (VBA.Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("@") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("Z")) Or (Asc(VBA.Mid(StringX, i + 1, 1)) >= VBA.Asc("a") And VBA.Asc(VBA.Mid(StringX, i + 1, 1)) <= VBA.Asc("z")) Then
       EncodeString = EncodeString & VBA.Mid(StringX, i + 1, 1)
    Else
       sByte = VBA.StrConv(VBA.Mid(StringX, i + 1, 1), vbFromUnicode)
       For j = LBound(sByte) To UBound(sByte)
           EncodeString = EncodeString & "%" & VBA.Hex(sByte(j))
       Next j
    End If
Next i
End Function
Public Function DecodeString(StringX As String) As String
Dim i As Long
Dim sByte() As Byte
Do Until i > VBA.Len(VBA.Trim(StringX)) ' - 1
   i = i + 1
   If VBA.Mid(StringX, i, 1) <> "%" Then
      DecodeString = DecodeString & VBA.Mid(StringX, i, 1)
   Else
      i = i + 1
      ReDim sByte(0) As Byte
      sByte(0) = Val("&H" & VBA.Mid(StringX, i, 2))
      If Val("&H" & VBA.Mid(StringX, i, 2)) > 128 Then
         i = i + 3
         ReDim Preserve sByte(1) As Byte
         sByte(1) = Val("&H" & VBA.Mid(StringX, i, 2))
         DecodeString = DecodeString & VBA.StrConv(sByte, vbUnicode)
      Else
         DecodeString = DecodeString & VBA.StrConv(sByte, vbUnicode)
      End If
      i = i + 1
   End If
Loop
End Function

解决方案 »

  1.   

    区别在这里
    字符          "A"     "啊"
    Unicode       00 41  A0 A1
    Ascii          41    A0 A1
      
      

  2.   


    可是怎样才能将 “214 208 185 250 49 50 51 200 203 195 241 97 98 99”
    转换成字符串“中国123人民abc" 呢?
      

  3.   

    Dim aa() As String
    Dim sByte() As Byte
    aa = Split("214 208 185 250 49 50 51 200 203 195 241 97 98 99", " ")
    ReDim sByte(UBound(aa) - LBound(aa) + 1) As Byte
    Dim i As Long
    For i = 0 To UBound(aa) - LBound(aa)
        sByte(i) = Val(aa(LBound(aa) + i))
    Next i
    MsgBox StrConv(sByte, vbUnicode)
      

  4.   

    thanks 女㊣爱 and 潇湘飞雨
      

  5.   

    Private Sub Command1_Click()Dim tstr As String
    Dim code(14) As Integer'code() = [ 214 208 185 250 49 50 51 200 203 195 241 97 98 99]
    code(0) = 214
    code(1) = 208
    code(2) = 185
    code(3) = 250
    code(4) = 49
    code(5) = 50
    code(6) = 51
    code(7) = 200
    code(8) = 203
    code(9) = 195
    code(10) = 241
    code(11) = 97
    code(12) = 98
    code(13) = 99For i = 0 To UBound(code())
        
        '如果为ASCII字符集则显示实现
        If code(i) <= 127 Then
            tstr = tstr & Chr(code(i))
        Else
           tstr = tstr & Chr("&H" & Hex(code(i)) & Hex(code(i + 1)))
           i = i + 1
        End If
        
    NextDebug.Print tstrEnd Sub