字符串的函数FastSplit Delphi

时间:2022-02-02 21:45:14

   2012年开始写博客,记录常用的技术知识点供大家交流。主要用到的开发环境是delphi2010.下面献上一段很好用的解析字符串的函数FastSplit。

 1 function FastSplit(const S: string; const Delimiter: string = ','): TStrings;
2 var
3 i, j: integer;
4 begin
5 Result := TStringList.Create;
6 i := 1;
7 j := Pos(Delimiter, S);
8 while j > 0 do
9 begin
10 Result.Add(Copy(S, i, j - i));
11 i := j + 1;
12 j := PosEx(Delimiter, S, i);
13 end;
14 Result.Add(Copy(S, i, Length(S)));
15 end;