熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

delphi 的分離字符串函數 split

2022-06-13   來源: Delphi編程 

  unit Unit;
  interface
  uses
    Windows Messages SysUtils Variants Classes Graphics Controls Forms
  Dialogs StdCtrls;

  type userarray=array of string;
  type
    TForm = class(TForm)
      Edit: TEdit;
      Button: TButton;
      procedure ButtonClick(Sender: TObject);
    private
      function split(s: string; dot: char): userarray;
      { Private declarations }
    public
      { Public declarations }
    end;

  var
    Form: TForm;

  implementation

  uses StrUtils;

  {$R *dfm}

  function TFormsplit(s:string;dot:char):userarray;
  var
  str:userarray;
  ij:integer;
  begin
  i:=;
  j:=;
  SetLength(str );

  while Pos(dot s) > do
  begin
  str[j]:=copy(sipos(dots)i);
  i:=pos(dots)+;
  s[i] := chr(ord(dot)+);
  j:=j+;
  end;
  str[j]:=copy(sistrlen(pchar(s))i+);
  result:=str;
  end;

  procedure TFormButtonClick(Sender: TObject);
  var
    ur:userarray;
    i:Integer;
  begin
    ur:=split(EditText;);
    for i := to do
    begin
      if length(ur[i])= then Exit;
      ShowMessage(ur[i]);
    end;
  end;
  end


From:http://tw.wingwit.com/Article/program/Delphi/201311/8530.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.