Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I polint off the string?

Status
Not open for further replies.

hayate

Programmer
May 17, 2003
7
JP
Hi,
I'm completely new to Delphi and I need help.
How can I split the string and add comma every three digits like that?
abc,def,ghi
I could split numbers using FormatFloat but string???

Thank you for any help.
 
This is quite easy to do. You should code a function similar to:
Code:
function InsertCommas ( const s: string ): string;
var
  p: integer;
begin
  result := s;
  p := Length(result) - 2;
  while p > 1 do begin
    Insert ( ',', result, p );
    dec ( p, 3 );
  end;
end;
and call it as follows (for example in response to a button click to put commas into the contents of Edit1 TEdit control):
Code:
  Edit1.Text := InsertCommas ( Edit1.Text );

Andrew
 
>towerbase

I tried the code you told me and it worked quite well.
Thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top