16,748
社区成员
发帖
与我相关
我的任务
分享
ShowMessage(FormatFloat(',#', 1232342345343543))
function SplitStr(const source: string; AChar: Char): string;
var
I, sLen, Count: Integer;
begin
Result := '';
sLen := Length(source);
if sLen = 0 then Exit;
for I := sLen downto 1 do
if ((sLen - I) mod 3 <> 0) or (I = sLen) then Result := source[I] + Result
else Result := source[I] + AChar + Result;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
s1, s2: string;
begin
s1 := '1234567890';
s2 := SplitStr(s1, ',');
ShowMessage(s2);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
s,ss:string;
i:Integer;
begin
s:=self.Edit1.Text;
if s='' then
Exit;
ss:='';
while s<>'' do
begin
if length(s)>=3 then
begin
ss:=','+copy(s,Length(s)-2,3)+ss;
s:=Copy(s,1,Length(s)-3);
end
else
begin
ss:=','+s+ss;
s:='';
end;
end;
ss:=Copy(ss,2,Length(ss)-1);
self.Edit2.Text:=ss;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s,ss:string;
i:Integer;
begin
s:=self.Edit1.Text;
if s='' then
Exit;
ss:='';
i:=0;
while s<>'' do
begin
if i=0 then
begin
ss:=s[1]+',';
s:=Copy(s,2,Length(s)-1);
end
else
begin
if length(s)>=3 then
begin
ss:=ss+copy(s,1,3)+',';
s:=Copy(s,4,Length(s)-3);
end
else
begin
ss:=ss+s+',';
s:='';
end;
end;
i:=i+1;
end;
self.Edit2.Text:=ss;
end;