请教高手怎么构造一很大的string,可以往里面塞字符串,而不是重新构造的???就好象java中的stringbuff类用copymemory函数的话怎么做呢???

解决方案 »

  1.   

    dim s as String
    dim i as longfor i = 1 to 10000
        s = s & cstr(i)
    next
      

  2.   

    'Example Name:CopyMemory
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim sSave As String, Cnt As Long, T As Long, Pos As Long, Length As Long
        Const mStr = "Hello "
        Length = Len(mStr)
        sSave = Space(5000 * Length) 'make buffer for justified comparison
        'Get the current tickcount
        T = GetTickCount
        Pos = 1
        sSave = Space(5000 * Length)
        For Cnt = 1 To 5000
          Mid(sSave, Pos, Length) = mStr
          Pos = Pos + Length
        Next Cnt
        'Show the results
        MsgBox "It took Visual basic" + Str$(GetTickCount - T) + " msecs. to add 5000 times a string to itself."
        'Get the current tickcount
        T = GetTickCount
        Pos = 0
        sSave = Space(5000 * Length)
        For Cnt = 1 To 5000
            CopyMemory ByVal StrPtr(sSave) + Pos, ByVal StrPtr(mStr), LenB(mStr)
            Pos = Pos + LenB(mStr)
        Next Cnt
        'Show the results
        MsgBox "It took CopyMemory" + Str$(GetTickCount - T) + " msecs. to add 5000 times a string to itself."
    End Sub
      

  3.   

    字符串有两种:变长与定长的字符串。穇变长字符串最多可包含大约 20 亿 ( 2^31)个字符。
    穇定长字符串可包含 1 到大约 64K ( 2^16 ) 个字符。注意    Public 定长字符串不能在类模块中使用。String 之字符码的范围是 0 到 255。字符集的前 128 个字符(0 到 127)对应于标准的 U.S. 键盘上的字符与符号。这前 128 个字符与 ASCII 字符集中所定义的相同后 128 个字符(128 到 255)则代表特殊字符,例如国际字符,重音符号,货币符号及分数。String 的类型声明字符为美圆号 ($)。
      

  4.   

    Dim str1 As String
    Private Sub Command1_Click()
    str1 = str1 & "122324klfdjlfj"
    End SubPrivate Sub Command2_Click()
    Print str1
    End Sub
    这样的str1不也是很大吗?