Hello, all!
Can anyone, tell me a vb6 code, that will search for a word in a text box and then replace it with an other! Well, i know the replace method from vb but it is not to fast! The text is 2000 words big!
Thanks in advance!
Printable View
Hello, all!
Can anyone, tell me a vb6 code, that will search for a word in a text box and then replace it with an other! Well, i know the replace method from vb but it is not to fast! The text is 2000 words big!
Thanks in advance!
Will the replaced text be equal, bigger or smaller in size?
Anyways, you could try using byte arrays. Optimized and compiled, it can be a lot faster than other replacing styles.
REPLACE is quite easy to code - are you experiencing that bad a pause when you use it on 2000 words?
I was curious about the same thing: it's not really that slow as far as I am concern and is really (as szlamany pointed out) simple to use so why complicating things ... that's how I see it. :wave:Quote:
Originally Posted by szlamany
I created a little test project and found that on my PC it only took less than 1ms to do a Replace on a textbox that containsed 2000 words and 16ms to do the same thing with 20,000 words.
Martin,
Just out of curiosity - if you still have the test available.
Sometimes it's more meaningful to see how many times you can do a REPLACE on 2000 words in a second - or let's say in 5 seconds - that microsecond means so little to the real world.
That way the original poster can get a real feel for how many replaces can occur in a reasonable amount of time...
Happy Holiday's...
Add a multiline textbox and a command button to Form1. Note that it may take a few seconds to fill the textbox at startup.
VB Code:
Option Explicit Private Declare Function GetTickCount Lib "kernel32" () As Long Private Sub Command1_Click() ' Place this code in any Sub or Function Dim lngStart As Long Dim lngFinish As Long Dim lngCounterOne As Long Dim lngCounterTwo As Long ' Record the start "time" lngStart = GetTickCount() ' Time it Text1.Text = Replace(Text1.Text, "little", "xxx") ' Record the finish "time" lngFinish = GetTickCount() ' Display the difference MsgBox CStr(lngFinish - lngStart) End Sub Private Sub Form_Load() 'http://www.vbforums.com/showthread.php?t=317562 Dim x As Integer For x = 1 To 2000 ' Create 20,000 words Text1.Text = Text1.Text & "This little sentence contains ten words, no more, no less. " Next End Sub
Something for me? Maybe the Replace method it's not to slow, but is there any other way?Quote:
Originally Posted by MartinLiss
Why do you need another way?
For using a faster code, for personal reasons!
I know that there is faster code, so i hope someone will know it...
Sure there is - write your own Replace() function in C++.Quote:
Originally Posted by DarkX_Greece
But as Martin said "Why do you need another way?" ;)
Quote:
Originally Posted by RhinoBull
Yes, he said that, but as you can see, i replied with "For using a faster code, for personal reasons!"
If you were willing to tell us why, then maybe we could help you.