The example in this article describes the usage of Delphi string separation function. Share it with everyone for your reference. The specific implementation method is as follows:
This example can separate the string s into several strings according to the representation of the string Separator and store them in the rs string list. The specific code is as follows:
Copy the code as follows: procedure SeparateTerms2(s:string;Separator:string;var rs:TStringList);
var
AStr: string;
idx: Integer;
ASubStr: string;
begin
AStr := Trim(s);
while Pos(Separator, AStr) > 0 do
begin
idx := Pos(Separator, AStr);
ASubStr := Copy(AStr, 1, idx - 1);
rs.Add(ASubStr);
AStr := Copy(AStr, idx + 1, Length(AStr));
end;
if AStr+'a' <> 'a' then rs.Add(AStr); //If there are remaining strings, store them in the string list
end;
I hope this article will be helpful to everyone's Delphi programming.