ss:='王洪:20050604:20070605'请问如何以':'为界,拆分成一个字符型数组的三个元素。
aa:array[0,2] of string
aa[0]='王洪'
aa[1]='20050604'
aa[2]='20070605'谢谢大家了。

解决方案 »

  1.   

    var
       ss:String;
       a:array[0..2] of string;
       tls:TStringList;
       i:integer;
    begin
       ss:='Íõºé:20050604:20070605';
       tls:=TStringList.Create;
       try
          tls.Text:=StringReplace( ss,':',#13,[rfReplaceAll]);
          for i:=0 to tls.Count-1 do a[i]:=tls.Strings[i];
       finally
          tls.Free;
       end;
       for i:=0 to 2 do   ShowMessage(a[i]);
    end;
      

  2.   

    var
       ss:String;
       a:array[0..2] of string;
       tls:TStringList;
       i:integer;
    begin
       ss:='王洪:20050604:20070605';
       tls:=TStringList.Create;
       try
          tls.Text:=StringReplace( ss,':',#13,[rfReplaceAll]);
          for i:=0 to tls.Count-1 do a[i]:=tls.Strings[i];
       finally
          tls.Free;
       end;
       for i:=0 to 2 do   ShowMessage(a[i]);
    end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TStringArray = Array of String;  TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        Function ParseString(sText:String):TStringArray;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      a:TStringArray;
      i:Integer;
    begin
      a:=ParseString('王洪:20050604:20070605');
      for i:=0 to High(a) do Showmessage(a[i]);
    end;function TForm1.ParseString(sText: String): TStringArray;
    var
      i:Integer;
      s:String;
    begin
      Result:=nil;
      While sText>'' do
      begin
        i:=Pos(':',sText);    if i>0 then
        begin
          s:=Copy(sText,1,i-1);
          Delete(sText,1,i);
        end
        else begin
          s:=sText;
          sText:='';
        end;    SetLength(Result,Length(Result)+1);
        Result[High(Result)]:=s;
      end;
    end;end.
      

  4.   

    我也来
    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      ss:string;
      aa:array[0..10] of string;
      l,i,s,j:Integer;
    begin
      ss:='王洪:20050604:20070605';
      j:=0;     // 数组的基数
      s:=1;     // 开始数
      l:=0;     // 长度
      if MidStr(ss,Length(ss),1)<>':' then ss:=ss+':';
      for i :=1  to Length(ss)  do begin
        if MidStr(ss,i,1)=':' then begin
          aa[j]:=MidStr(ss,s,l);
          inc(j);
          s:=i+1;
          l:=0;
        end else begin
          inc(l)
        end;
      end;  //For
      ShowMessage(aa[0]+'-'+aa[1]+'-'+aa[2]);
    end;