procedure TForm1.Button1Click(Sender: TObject); const Res = 'f[1]+f[8]+f[10]+f[22]'; var str: string; s: TStringList; a: array of integer; i: integer; begin str := StringReplace(Res, '+', ',', [rfReplaceAll]); s := TStringList.Create; s.CommaText := str; SetLength(a, s.Count); for i := 0 to s.Count - 1 do begin a[i] := StrToInt(Copy(s.Strings[i], 3, Length(s.Strings[i]) - 3)); ShowMessage(IntToStr(a[i])); end; end;
procedure ParseString(const Source: string; S: TStrings); var I, J: Integer; begin S.Clear; I := 1; J := 1; repeat I := PosEx('[', Source, I + 1); J := PosEx(']', Source, J + 1); if I < J then S.Add(Copy(Source, I + 1, J - I - 1)); until I = 0; end;procedure TForm1.Button1Click(Sender: TObject); begin ParseString('f[1]+f[8]+f[10]+f[22]', ListBox1.Items); end;
哈哈 太谢谢各位了 特别鸣谢 budded(System is bussy!) , luke5678(奇异) 两位大虾!!谢谢
你自己看一下帮助吧。
const
Res = 'f[1]+f[8]+f[10]+f[22]';
var
str: string;
s: TStringList;
a: array of integer;
i: integer;
begin
str := StringReplace(Res, '+', ',', [rfReplaceAll]);
s := TStringList.Create;
s.CommaText := str;
SetLength(a, s.Count);
for i := 0 to s.Count - 1 do
begin
a[i] := StrToInt(Copy(s.Strings[i], 3, Length(s.Strings[i]) - 3));
ShowMessage(IntToStr(a[i]));
end;
end;
var I, J: Integer;
begin
S.Clear;
I := 1;
J := 1;
repeat
I := PosEx('[', Source, I + 1);
J := PosEx(']', Source, J + 1);
if I < J then
S.Add(Copy(Source, I + 1, J - I - 1));
until I = 0;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ParseString('f[1]+f[8]+f[10]+f[22]', ListBox1.Items);
end;
特别鸣谢 budded(System is bussy!) , luke5678(奇异) 两位大虾!!谢谢