• Welcome to Valhalla Legends Archive.
 

VB's native Replace function

Started by o.OV, February 04, 2004, 11:25 AM

Previous topic - Next topic

o.OV

@_<
Is it just me.. or is VB's Replace function really really slow..

That is.. if there is padding or it is same length strings.



Public Declare Function GetTickCount Lib "kernel32.dll" () As Long

Public Sub test3()

   Dim t As Long, x As Long, test As String, faketest As String, something As Long
   test = Space$(100000)
   theword = "test"
   replacer = "fake"
   something = 1
   
   For x = 0 To (100000 / 4) - 1
       Mid$(test, (x * 4) + 1, 4) = theword
   Next x
   
   faketest = test
   t = GetTickCount
   Do
       something = InStr(something, faketest, theword)
       If something Then
           Mid$(faketest, something, 4) = replacer
       End If
   Loop While something
   MsgBox "instr: " & GetTickCount - t
   
   faketest = test
   t = GetTickCount
   faketest = Replace(faketest, theword, replacer)
   MsgBox "replace: " & GetTickCount - t
   
End Sub

If the facts don't fit the theory, change the facts. - Albert Einstein

TheMinistered

So, write your own in assembly that complies to the way visual basic passes/returns data and i'll implement it into vb natively.