delphi怎么把”0,1,2,3,4,5,6,7,8,9,10,11,“这个字符串截取成 0 1 2 3 4 5 6 7 8 9 10 11

2024-12-14 21:13:21
推荐回答(3个)
回答1:

var
sl :TStringList;
s :string;
i :Integer;
begin
s := '0,1,2,3,4,5,6,7,8,9,10,11,';
s := StringReplace(s, ',', ',', [rfReplaceAll]);
sl := TStringList.Create;
try
sl.DelimitedText := s;
for i := 0 to sl.Count - 1 do
begin
s := Trim(sl.Strings[i]);
if s <> '' then
ShowMessage(s);
end;
finally
FreeAndNil(sl);
end;
end;

回答2:

直接将其中的 逗号 替换就可以了吧?截取是什么意思

以下是替换的示例代码:

procedure TForm1.Button1Click(Sender: TObject);
var s: string;
begin
s := '0,1,2,3,4,5,6,7,8,9,10,11,';
ShowMessage(StringReplace(s,',',' ',[rfReplaceAll]));
end;

回答3:

stringreplace(s,',',' '.[])