zoukankan      html  css  js  c++  java
  • Explode TArray

    function Explode(const Separator, S: string; Limit: Integer = 0): TArray;
    var
    SepLen : Integer;
    F, P : PChar;
    ALen, Index : Integer;
    begin
    SetLength(Result, 0);
    if (S = '') or (Limit < 0) then
    Exit;
    if Separator = '' then
    begin
    SetLength(Result, 1);
    Result[0] := S;
    Exit;
    end;
    SepLen := Length(Separator);
    ALen := Limit;
    SetLength(Result, ALen);

    Index := 0;
    P := PChar(S);
    while P^ <> #0 do
    begin
    F := P;
    P := StrPos(P, PChar(Separator));
    if (P = nil) or ((Limit > 0) and (Index = Limit - 1)) then
    P := StrEnd(F);
    if Index >= ALen then
    begin
    Inc(ALen, 5); //
    SetLength(Result, ALen);
    end;
    SetString(Result[Index], F, P - F);
    Inc(Index);
    if P^ <> #0 then
    Inc(P, SepLen);
    end;
    if Index < ALen then
    SetLength(Result, Index); //
    end;


    type
    TArray = array of string;

    .....

    var
    arr: TArray;
    begin
    arr := explode(',', 'Mark,Michel,segment,');
    end;

  • 相关阅读:
    数组列简介
    linq的使用
    StringBuilder对象
    使用类来继承接口
    设置函数库并引用
    循环语句
    cut和paste用法
    uniq用法
    shell中数组的应用
    委派
  • 原文地址:https://www.cnblogs.com/yzryc/p/6109983.html
Copyright © 2011-2022 走看看