有一个字符串,里面即有英文,也有汉字,请问在VB里怎么得出一个字符串所占的字节数,用Len函数不行。

解决方案 »

  1.   

    lenb(strconv(字符串,vbFromUnicode ))
      

  2.   

    Public Function LenC(ByVal pstr As String) As Long
        Dim chr As String
        Dim i As Long
        Dim lngRet As Long    lngRet = 0    For i = 1 To Len(pstr)
            chr = Mid(pstr, i, 1)        If AscW(chr) > 256 Then
            'a chinese char
                lngRet = lngRet + 2
            Else
            'a english char
                lngRet = lngRet + 1
            End If
        Next i    LenC = lngRet
    End Function在Foxpro 中用LenC就可以了,在VB中可能需要加入以上的东东
      

  3.   

    lenb(strconv(字符串,vbFromUnicode ))
    是有一点点问题的,你试试‘会'就知道了
      

  4.   

    LenB(StrConv("在中abc", vbFromUnicode))
      

  5.   


    '计算字符串的真实长度
    Private Function LenTruth(str As String) As Long
        Dim lngU As Long
        Dim lngI As Long
        
        lngU = Len(str)
        For lngI = 1 To lngU
            If Asc(Mid(str, lngI, 1)) < -2818 Then
                LenTruth = LenTruth + 2
            Else
                LenTruth = LenTruth + 1
            End If
        Next
        
    End Function
      

  6.   

    Private Function GetStrB(ByVal strString As String, ByVal iLenB As Long)
       GetStrB = StrConv(LeftB(StrConv(strString, vbFromUnicode), iLenB), vbUnicode)
    End Function
      

  7.   

    Private Function GetStrB(ByVal strString As String, ByVal iLenB As Long)
       GetStrB = StrConv(LeftB(StrConv(strString, vbFromUnicode), iLenB), vbUnicode)
    End Function
      

  8.   

    ufcr(蓝石) 和szyhy810518(yhy) 的代码都可以,其实是一样的