Re: Remove spaces in CSV file using VB6

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Wed, 5 Apr 2006 11:21:47 +0100, "Mike Williams"
<Mike@xxxxxxxxxxxxxxxxx> wrote:

<snip>

Actually that's the way I would do it Jerry. Certainly a lot faster than
multiple use of the Replace function, and it certainly isn't worth bothering
using a Byte array instead of a string unless speed is critical (which I
don't think it really is in the OP's case). The only snag is the the code as
above will remove each entire group of spaces where there is more than one
in succession but will leave single spaces untouched, which I don't think he
wanted. However, to remove all "extra" spaces (leaving a single space at
each location) you just need to make the following slight modification, by
changing:

<snip>

I am pretty sure that the OP wants to keep the single space between
BOD and 5

2006-01-28 08:57:28.887000000,TNS,NINF,BOD 5 ,250,2006-01-29

To be honest I would probably process this line by line and field by
field using a buffer to read and another to write.

At some stage the OP is going to need to do Field specific
modifications, which would mean a total re-write, or at best a line by
line post/pre-pass

Also the current method has zilch ability to detect bad data
- and, as with production systems, detecting problems gets
exponentially more 'expensive' the further it gets down the line.

However, my impression was that he wanted a 'quick fix' so I decided
not to give him a lecture <g>

I've a feeling that it would be a lot faster on a Byte Array as one
would shuffle the Bytes down inplace, then do a ReDim Preserve which
does not move the data if one is resizing down
Hmm... one could do the same with StrPtr and MoveMemory on the raw
string ...
.



Relevant Pages

  • Re: A repost - Permuting SPACES within a String of words
    ... Then you should check for empty cells array ... Use ubound to find out how many cells your array contains ... > a) where there is no space between any of the words in the string ... > together and the lone word is separated by a single space. ...
    (microsoft.public.excel.programming)
  • Re: Comparing 2 strings for matches in any order
    ... > single space delimiter). ... I need to compare to Column A row 2 and so forth. ... > Then the whole process repeats, matching Column B's bear to the array ... > determine that there was a positive match made for that string in ...
    (microsoft.public.access.modulesdaovba)
  • Re: sizeof()s strange behviour
    ... Since you use these to store the results of sizeof operations, ... If you want the size of the array, ... The null character that terminates the string may not be terribly ...
    (comp.lang.c)
  • Re: Writing an XML document via Javascript.
    ... where - xmlArray.join- returns a string that each string value ... stored in the array, in order, joined together using the empty string ... But then the problem of recovering the original XML source form the ...
    (comp.lang.javascript)
  • Re: Something that really annoys me in Delphi ...
    ... > string should always be done by means of an array ... ...
    (comp.lang.pascal.delphi.misc)