大家试试 
format("111011101110000101010011100011","00000000000000000000000000000000")我得到的是00111011101110000000000000000000不解中.忘高手解答! 谢谢

解决方案 »

  1.   

    只是想把2进制补齐成32位.我读取的是一个long
    其他的都行,就是这个有问题,是不是太特殊了?
      

  2.   

    没有这样做过,我想设计者也没有这样做过
    如果只是测试这个函数,都可以试下
    如果真得用Format函数做这个,好像没有意义
      

  3.   

    你的这个操作其实在format函数里面先把字符串转换成数值型数据再进行处理,这时候并不把你的数字当作二进制数据进行处理而是十进制数,这个数字转为数值型以后只有single和double能够容纳,但这两个类型的精度没办法达到你的要求。所以得出的结果肯定和你想要的结果不同。
     
    对于字符串补齐这样简单规则没必要用format,因为format内部有一大堆的转换规则,一来效率不高二来有这样那样的限制。自己写一个函数处理很简单的'字符串补位函数
    'strInput 需要处理的字符串 intFillLen补齐后长度 strFillString补位字符 blnFillBefore是否在前面补位
    Private Function test(strInput As String, intFillLen As Integer, strFillString As String, Optional blnFillBefore As Boolean = True) As String
        If intFillLen < Len(strInput) Then test = strInput: Exit Function
        If blnFillBefore Then
            test = String(intFillLen - Len(strInput), strFillString) & strInput
        Else
            test = strInput & String(intFillLen - Len(strInput), strFillString)
        End If
    End Function调用举例
    Dim a As String
    a = "111011101110000101010011100011"
    Debug.Print test(a, 32, "0")
    Debug.Print test(a, 32, "E", False)输出
    00111011101110000101010011100011
    111011101110000101010011100011EE