Delphi中Split函数的源码实现是怎样的?
- 内容介绍
- 文章标签
- 相关推荐
本文共计121个文字,预计阅读时间需要1分钟。
plaintextfunction Split(const Separator: array of string; Count: Integer; Options: TStringSplitOptions): TArray;var P, Total, Index: Integer; S, ToSplit: string;begin Total :=0; ToSplit :=Self; P :=1;end;
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;
本文共计121个文字,预计阅读时间需要1分钟。
plaintextfunction Split(const Separator: array of string; Count: Integer; Options: TStringSplitOptions): TArray;var P, Total, Index: Integer; S, ToSplit: string;begin Total :=0; ToSplit :=Self; P :=1;end;
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;

