Link to home
Start Free TrialLog in
Avatar of shawn857
shawn857

asked on

How to use "HVStringBuilder" module...?

Hi experts, does anyone have any experience using the "HVStringBuilder" unit found here:

https://code.google.com/p/omnithreadlibrary/source/browse/#svn/trunk/src

Basically, I'd just like to see a simple code example on how to utilize/call it.

Thanks!
    Shawn

P.S: I use Delphi 7
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shawn857
shawn857

ASKER

I don't quite understand this line of code:

mystr.Append('(').Append(i).Append('.) ').Append('position').Append(#13#10);

Thanks
   Shawn
I would suspect the output would look like this...

(1.) position<cr><lf>
(2.) position<cr><lf>
(3.) position<cr><lf>
(4.) position<cr><lf>
(5.) position<cr><lf>
(6.) position<cr><lf>
(7.) position<cr><lf>
(8.) position<cr><lf>
(9.) position<cr><lf>
(10.) position<cr><lf>

each call to append adds a string to the end of the stringbuilder...

The code could be rewritten as

function GetMyList: String;  
var 
  i: integer;
begin
  Result := ''
  for i := 1 to 10 do 
    Result :=  Result + '(') + IntToStr(i) + '.) position' + #13#10;
end;

Open in new window

what output do you need?
Thanks for that guys.

Well, I have a FOR loop where I'm building up a string variable one character at a time - basically like this:

bigstring:= '';
For i := 0 to UpperLimit do
begin
   bigstring := bigstring + buffer[i];
end;

Open in new window


I'm guessing using StringBuilder, that would translate to something like:

bigstring:= TStringBuilder.Create;
bigstring.Clear;
For i := 0 to UpperLimit do
begin
   bigstring.Append(buffer[i]);
end;

Open in new window


Is this right? But after this is done, how do you access the contents of "bigstring"? Do I just refer to it as simply "bigstring" in my code, or something else?

Thanks
    Shawn
just use it where need it:
s := bigstring.ToString; //string to string

Open in new window

or...
 if Pos('%',bigstring.ToString)>0 then ....

Open in new window

Thank you Sinisa, it works fine.

Did you know that this HVStringBuilder routine is much, much, MUCH faster than doing this:

bigstring := bigstring + buf[z];

It is a HUGE difference.

Thanks
    Shawn
This is know issue with string management routines (memory management behind)  in Delphi. So, this is why I use FastMM.
So if FastMM is utilized, then normal Delphi string management is close in performance to HVStringBuilder?

Thanks
   Shawn
cannot tell, but it is worth to try.
May look at this EE question or this too.
Thank you Sinisa.

Cheers
    Shawn