Re: Need help which way is fastest to pick out a segment from a string
- From: "Mike Williams" <mikea@xxxxxxxxxxxxxxxxx>
- Date: Fri, 16 May 2008 20:05:26 +0100
"Les" <Les@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:475C597E-DFCE-4DA5-A676-F8A3531B80E9@xxxxxxxxxxxxxxxx
I am using VB-6 and I have about 200,000 lines of text which
include spaces and I want suggestions as far as which way is
the fastest way starting from the beginning of the line to grab
the left side of the string up to the first blank space. What I
have tried that works is the following:
stringSelected=left$(string,instr(1,string," ",vbBinarCompare)-1)
It seems this takes considerably longer then I want.
Split returns an array of substrings and even if you ask it to return just one element it will be massively slower than Left$. On a quick test I've just performed it actually takes about six times longer than the Left$ function. In fact the Left$ function is quite fast, especially if you are using it with vbBinaryCompare as you are currently doing. There may just be a little to gain by pulling the data into a Byte array and dealing with it as raw byte data, but for this specific task I very much doubt that it will be much faster.
What sort of speed are you looking for, by the way? You have said that Left$ takes "considerably longer than I want", but personally I have found it to be very fast. How fast do you want this thing to go? I have just created an array of 200,000 strings of random characters each with a length varying randomly between 36 and 72 characters and with the first space character in each string varying randomly in the range 12th to 32nd character position. If I then run a code loop on that array of 200,000 strings extracting the substring you have requested the code deals with the entire array, returning all 200,000 substrings, in just one tenth of a second. That's dealing with the strings at a rate of two million strings per second, and this is running on what is by today's standards a fairly slow machine. How much faster do you want it to go that that?
Mike
.
- References:
- Prev by Date: Re: Need help which way is fastest to pick out a segment from a string
- Next by Date: Re: Need help which way is fastest to pick out a segment from a st
- Previous by thread: Re: Need help which way is fastest to pick out a segment from a string
- Next by thread: Re: Need help which way is fastest to pick out a segment from a string
- Index(es):
Relevant Pages
|