Delphi中,根据字符串,拆分字符串,相当于vb中的split函数

来源:互联网 发布:淘宝网雪纺衫 编辑:程序博客网 时间:2024/05/21 15:13

//根据字符串,拆分字符串,相当于vb中的split函数
function SplitString(const Source,ch:string):TStringList;
var
  temp:String;
  i:Integer;
begin
  Result:=TStringList.Create;
  //如果是空自符串则返回空列表
  if Source=''
  then exit;
  temp:=Source;
  i:=pos(ch,Source);
  while i<>0 do
  begin
     Result.add(copy(temp,0,i-1));
     Delete(temp,1,i);
     i:=pos(ch,temp);
  end;
  Result.add(temp);
end;

 


unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls;  
   
  type  
      ta=array   of   array   of   string;  
      TForm1   =   class(TForm)  
          Memo1:   TMemo;  
          Button1:   TButton;  
          procedure   Button1Click(Sender:   TObject);  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
          procedure   SetTaIn(a:ta);  
          function   GetTaIn:ta;  
      end;  
   
   
  var  
      Form1:   TForm1;  
   
  implementation  
   
  {$R   *.dfm}  
   
  procedure   TForm1.SetTaIn(a:Ta);  
  var   i,j:integer;  
  begin  
      for   i:=Low(a)   to   High(a)   do  
          for   j:=Low(a[i])   to   High(a[i])   do  
              Memo1.Lines.Add(a[i][j]);  
  end;  
   
  function   TForm1.GetTaIn:Ta;  
  var   a:Ta;   i,j:integer;  
  begin  
        SetLength(a,3,3);  
        for   i:=0   to   2   do  
            for   j:=0   to   2   do  
                a[i][j]:=InttoStr((i+1)*(j+1));  
        Result:=a;  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var   a:Ta;i,j:integer;  
  begin  
      a:=GetTaIn;  
      SetTaIn(a);  
  end;  
   
  end.  

 

原创粉丝点击