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
shawn857Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
maybe like this:
function GetMyList: String;  
var
  mystr: TStringBuilder;
begin
  mystr := TStringBuilder.Create;
  try
    for i := 1 to 10 do 
    begin
        mystr.Append('(').Append(i).Append('.) ').Append('position').Append(#13#10);
    end;
    Result := mystr.ToString;
  finally 
    FreeAndNil(mystr); 
  end;
end;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shawn857Author Commented:
I don't quite understand this line of code:

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

Thanks
   Shawn
House_of_DexterCommented:
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

Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Sinisa VukSoftware architectCommented:
what output do you need?
shawn857Author Commented:
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
Sinisa VukSoftware architectCommented:
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

shawn857Author Commented:
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
Sinisa VukSoftware architectCommented:
This is know issue with string management routines (memory management behind)  in Delphi. So, this is why I use FastMM.
shawn857Author Commented:
So if FastMM is utilized, then normal Delphi string management is close in performance to HVStringBuilder?

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

Cheers
    Shawn
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.