H
Harry Strybos
Tom Shelton said:Which of course I know. I spent a few years as a vb programmer myself
It can - but not in the way I was using it. The constructor I used set
the
max capcity, so the internal buffer can not grow beyond that. I also set
the
intial capacity so that the buffer is pre-allocated. Basically, the
buffer is
a fixed size - and will never grow or shrink... Basically avoiding a ton
of
memory allocations and string creation. In fact, the same buffer is used
in
every iteration of both .net algorithms. Setting the length = 0 basically
resets the internal pointer back to the begining of the buffer...
No, it was about if there was a way to accomplish the same task as the mid
statement that was faster. The answer is - yes.
I think most of us are aware of the fact that the vb.net mid is slower
then
the vb6 mid. But, any experienced .net developer is not going to bother
with
mid or strings in general for this kind of work. They are going to use a
StringBuilder - which is specifically designed for this kind of problem.
Well Tom, without getting drawn into the cynical "any experienced .net
developer is not going to bother", let me ask you how you would use the
StringBuilder to replace n characters at position x with some other
characters. eg I have a string "11111111111111111111111111" and I want to
replace "111" starting at position 6 with "222". You can't use the Replace
method.
Tom, I am dealing with bank files that have fixed length fields in a fixed
length string containing some filler fields that are left blank for bank use
or return of data. I also have to parse these rows at a later date to
extract various fields. Seems the Mid Function/Statement is well suited for
this task, although I do appreciate the speed advantages of the
StringBuilder class. Given that I typically would be building just 3-4k of
rows, the speed difference is marginal. I was, however, interested in
whether there was a more efficient method and your suggestions, (adding that
I use the StingBuilder class regularly) were most helpful, though not
exactly what I need.
I did reply to Armin Zingler and added some alternate code. Sadly, I have
not had a chance to test it for speed.