如何写出Left、Right、Mid等字符串处理函数,而且代码中不能使用任何VB提供的字符串处理函数???

解决方案 »

  1.   

    第一个left
    Private Sub Command1_Click()
        Dim StrA    As String
        Dim IntLen  As Long
        
        Dim StrC    As String
        
        StrA = "ABCDEFGHIJKLMN"
        IntLen = 5
        
        'StrC = Left(StrA, IntLen)
        StrC = funGetLeft(StrA, IntLen)
        MsgBox (StrC)
        
    End SubFunction funGetLeft(ByVal strValue As String, ByVal index As Integer) As String
        Dim str2     As String
        Dim abyte1()     As Byte
        Dim abyte2()     As Byte
        abyte1 = strValue
        For i = 0 To index * 2 - 1
            ReDim Preserve abyte2(i) As Byte
            
            abyte2(i) = abyte1(i)
        Next
        funGetLeft = abyte2
    End Function