急!!!请高手帮忙!用 StrConv("",vbUnicode)可以得到 Unicode ,但现在不可以用 StrConv 函数(不要问我为什么不用这个函数),那么该怎么做?

解决方案 »

  1.   

    可以使用StrConv 函数吧 :)
      

  2.   

    嘿嘿,其实真的可以哦!Private Sub Form_Load()
        Dim b() As Byte
        Dim s As String
        s = "AB"
        b = s
        Debug.Print b(0), b(1), b(2), b(3)
    End Sub
      

  3.   


    另外我真的很想知道,为什么不用StrConv ?
      

  4.   

    AscW   返回字符串第一个字符的 Unicode 字符代码。 
    ChrW   返回包含指定 Unicode 字符代码的字符串。 ChrW (AscW("h"))
      

  5.   

    正确的答案应该是调用api函数MultiByteToWideChar
      

  6.   

    rainstormmaster(暴风雨 v2.0)正确,但是我就是不知道该怎么用,大哥好心,给我完整的代码吧。
    Chice_wxg(学)(习) 
    不用的原因是因为所有汉字的 UTF-8 都是3个字节,只有 utf-16 才是2个字节,StrConv 只支持 utf-16,不支持 utf-8
    flyingscv(zlj)
    拜托,我说了不能用这个了啊
      

  7.   

    是要将utf-8转换为unicode吧?是的话,参考:
    'Utf8 转换为 Unicode
    Public Function UTF8_Decode(ByVal s As String) As String   Dim lUtf8Size        As Long
       Dim sBuffer          As String
       Dim lBufferSize      As Long
       Dim lResult          As Long
       Dim b()              As Byte   If LenB(s) Then
          On Error GoTo EndFunction
          b = StrConv(s, vbFromUnicode)
          lUtf8Size = UBound(b) + 1
          On Error GoTo 0
          'Set buffer for longest possible string i.e. each byte is
          'ANSI<=&HFF, thus 1 unicode(2 bytes)for every utf-8 character.
          lBufferSize = lUtf8Size * 2
          sBuffer = String$(lBufferSize, vbNullChar)
          'Translate using code page 65001(UTF-8)
          lResult = MultiByteToWideChar(CP_UTF8, 0, b(0), _
             lUtf8Size, StrPtr(sBuffer), lBufferSize)
          'Trim result to actual length
          If lResult Then
             UTF8_Decode = Left$(sBuffer, lResult)
             'Debug.Print UTF8_Decode
          End If
       End IfEndFunction:End Function
    'Unicode转换为UTF-8.
    Public Function UTF8_Encode(ByVal strUnicode As String) As String
       Dim TLen             As Long   TLen = Len(strUnicode)
       If TLen = 0 Then Exit Function   Dim lBufferSize      As Long
       Dim lResult          As Long
       Dim b()              As Byte
       'Set buffer for longest possible string.
       lBufferSize = TLen * 3 + 1
       ReDim b(lBufferSize - 1)
       'Translate using code page 65001(UTF-8).
       lResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(strUnicode), _
          TLen, b(0), lBufferSize, vbNullString, 0)
       'Trim result to actual length.
       If lResult Then
          lResult = lResult - 1
          ReDim Preserve b(lResult)
          UTF8_Encode = StrConv(b, vbUnicode)
       End IfEnd Function
      

  8.   


    原来如此。那么我的方法就别用了。对汉字编换出来不是Unicode编码   ^_^
      

  9.   

    rainstormmaster(暴风雨 v2.0)   老大,我先调试看看,如果OK,马上结帖,所有人都有分,感谢大家。本回帖以下的都没有分。另外,另外哪个问题一并结贴, rainstormmaster(暴风雨 v2.0) 你知道的,呵呵
      

  10.   

    Public Function UTF8_Encode(ByVal strUnicode As String) As String
    ?????????????????????????????????ByVal strUnicode As String不是要用 Byte 吗?
      

  11.   

    另外,最后还是用这个来转换 UTF-8 的UTF8_Encode = StrConv(b, vbUnicode)唉!!!
      

  12.   

    //ByVal strUnicode As String
    不是要用 Byte 吗?最好用byte,其实上面的这段是一个老外写的,我没细看//另外,最后还是用这个来转换 UTF-8 的
    UTF8_Encode = StrConv(b, vbUnicode)这个不用StrConv一样可以实现
      

  13.   

    //另外,最后还是用这个来转换 UTF-8 的
    UTF8_Encode = StrConv(b, vbUnicode)这个不用StrConv一样可以实现我就是要不用 StrConv 实现的代码啊!!!
      

  14.   

    //UTF8_Encode = StrConv(b, vbUnicode)
    这是将ansi转化为unicode,你确定是需要这个吗?
      

  15.   

    是的,所有汉字的 UTF-8 都是3个字节,只有 utf-16 才是2个字节,StrConv 只支持 utf-16,不支持 utf-8所以我要不用 StrConv 函数的方法转 unicode
      

  16.   

    这里有个模块,应该可以满足你的要求:
    http://www.netpadd.com/source.php?topic=modInCodePage.bas
      

  17.   

    是的,所有汉字的 UTF-8 都是3个字节,只有 utf-16 才是2个字节,StrConv 只支持 utf-16,不支持 utf-8..............................................真是这样马?unicode问题困扰我一年了,所有的贴子我都看过了。。