VB中字符串数组快速复制的一种方法

Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, source As Any, ByVal numBytes As Long)
Private Declare Sub ZeroMemory Lib "kernel32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)

Private Sub CopyStringArray(source() As String, dest() As String)
    Dim mLbound As Long, mUbound As Long, numBytes As Long
    mLbound = LBound(source)
    mUbound = UBound(source)
    numBytes = (mUbound - mLbound + 1) * 4
    ReDim dest(mLbound To mUbound) As String
    CopyMemory ByVal VarPtr(dest(mLbound)), ByVal VarPtr(source(mLbound)), numBytes
End Sub

你可能感兴趣的:(字符串)