The 5-10-2, 5-6-3, and how to make up two complement adding 0, volume to the 05-06-03 05-10-02
CodePudding user response:
The function MyStrFunc (const AStr: string) : string;
Var
I: integer;
S: a string;
The begin
S:=';
Result:=';
For I:=1 to length (AStr) do
The begin
If AStr [I] in [' 0 '... '9'] then
S:=s + AStr [I]
The else begin
If s<> "' then
The begin
If length (s) & gt; 2 then s:=Copy (s, 1, 2);
Result: the result=+ FormatFloat (' 00 'StrToInt (s)) + AStr [I];
S:=';
end;
end;
end;
If s<> 'then the result: the result +=FormatFloat (' 00' StrToInt (s));
end;
Procedure TForm1. Button1Click (Sender: TObject);
The begin
//edit1. Text:='5-6-3 5-10-2';
Edit2. Text:=MyStrFunc (edit1. Text);
end;
CodePudding user response:
Format (% d, 0.2 5)CodePudding user response:
In the blank space split large group first, and then to '-' split group, for team each item format, then assembled into a string:
The unit Unit1;
Interface
USES the
Winapi. Windows, Winapi Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
The Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. StdCtrls;
Type
TForm1=class (TForm)
Edt1: TEdit;
Lbl1: TLabel;
Btn1: TButton;
Procedure btn1Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;
Var
Form1: TForm1;
Implementation
{$R *. DFM}
Procedure TForm1. Btn1Click (Sender: TObject);
Var
SText: string;
SArr, sArr1: TArray;
I, j: Integer;
The begin
SText:=Trim (edt1. Text);
SArr:=sText. Split ([...]);
If Length (sArr) & gt; 0 then
The begin
For I:=Low (sArr) to High (sArr) do
The begin
SArr1:=sArr [I]. The Split (/'-');
If Length (sArr1) & gt; 0 then
The begin
For j:=Low (sArr1) to High (sArr1) do
The begin
SArr1 [j] :=sArr1 [j]. Trim;
SArr1 [j] :=FormatFloat (' 00 'StrToIntDef (sArr1 [j], 0));
//sArr1 [j] :=s1;
end;
SArr [I] :=string. Join (' - 'sArr1);
end;
end;
Lbl1. Caption:=string. Join (' ', sArr);
end;
end;
End.