Delphi的Split函数如何改写以适应长尾词处理?
- 内容介绍
- 文章标签
- 相关推荐
本文共计231个文字,预计阅读时间需要1分钟。
plaintext函数 Split 用于将字符串按指定的分隔符分割成数组。参数包括:- Separator:分隔符数组- Count:返回数组的最大长度- Options:分割选项
代码如下:var P: Integer; Total: Integer; Index: Integer; S, ToSplit: string;Total :=0; ToSplit :=Self; P :=0;while P
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;
本文共计231个文字,预计阅读时间需要1分钟。
plaintext函数 Split 用于将字符串按指定的分隔符分割成数组。参数包括:- Separator:分隔符数组- Count:返回数组的最大长度- Options:分割选项
代码如下:var P: Integer; Total: Integer; Index: Integer; S, ToSplit: string;Total :=0; ToSplit :=Self; P :=0;while P
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;

