Delphi分割字符串函数Split源码
function TStringHelper.Split(const Separator: array of string; Count: Integer; Options: TStringSplitOptions): TArray<string>; var P: Integer; Total: Integer; Index: Integer; S, ToSplit: string; begin Total := 0; ToSplit := Self; P := ToSplit.IndexOfAny(Separator, Index); while (P >= 0) and (Total < Count) do begin S := ToSplit.Substring(0, P); if (S <> Empty) or ((S = Empty) and (Options <> ExcludeEmpty)) then begin Inc(Total); SetLength(Result, Total); Result[Total - 1] := S; end; ToSplit := ToSplit.Substring(P + Separator[Index].Length); P := ToSplit.IndexOfAny(Separator, Index); end;
好的代码像粥一样,都是用时间熬出来的