如一个字符串'1,2,3,4,5,6,7,8,9',我要以","为分隔符将这个字符串分隔成一个数组,结果是a[0]=1,a[1]=2.........。

解决方案 »

  1.   

    var S: string;
    FUNCTION StringToStrings(S: string):Tstrings;
    var
    Ss: tstrings;
    i:int;
    begin
      Ss := tstrings.create(nil);
      i:= Pos(',', S);
      while i> 0 do
      begin
        Ss.add(copy(s,1,i); 
        s:=copy(s,i,length(s) - i);
      end;
      result:=Ss;
    end;
      

  2.   

    procedure TForm1.Button4Click(Sender: TObject);
    var
      s:string;
      i,j,m,n:integer;
      str:TStringList;
      l:array[0..12] of string;
    begin
      str:=TStringList.Create;
      str.Clear;
      s:='1,2,3,4,5,6,7';
      i:=length(s);
      for j:=0 to i-1 do
      begin
        if s[j]=',' then
          str.Add(inttostr(j));
      end;
      m:=str.Count;
      l[0]:=copy(s,1,strtoint(str.Strings[0])-1);
      showmessage(l[0]);
      for n:=1 to m-1 do
      begin
        l[n]:=copy(s,strtoint(str.Strings[n-1])+1,strtoint(str.Strings[n])-strtoint(str.Strings[n-1])-1);
        showmessage(l[n]);
      end;
      if strtoint(str.Strings[m-1])<i then
      begin
        l[m]:=copy(s,strtoint(str.Strings[m-1])+1,i-strtoint(str.Strings[m-1]));
        showmessage(l[m]);
      end;end;
      

  3.   

    var
     a:array of integer;
     s:string;
     i:integer;
    begin
      s:='1,2,3,4,5,6';
      setlength(a,0);
      while pos(',',s)>0 do
      begin
        setlength(a,high(a)+2);
        a[high(a)]:=strtoint(copy(s,1,pos(',',s)-1));
        s:=copy(s,pos(',',s)+1,length(s)-pos(',',s));
      end;
      setlength(a,high(a)+2);
      a[high(a)]:=strtoint(s);
      self.Caption:='';
      for i:=0 to high(a) do
      self.Caption:=self.Caption+inttostr(a[i]);
      setlength(a,0);
      a:=nil;
    end;
      

  4.   


    可以分字符的
    var a:array of string;
    s:string;
    i,j:integer;
    begin
      s:=edit1.text;
      i:=0;
      while pos(',',s)>0 do
      begin
        i:=i+1;
        setlength(a,i+1);
        setlength(a,high(a)+2);
        a[i-1]:=copy(s,1,pos(',',s)-1);
        s:=copy(s,pos(',',s)+1,length(s)-pos(',',s));
      end;
        a[I]:=s;
        for j:=0 to i do
        showmessage(a[j]) ;end;
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    Var a:TStringList;
    Begin
    a :=TStringList.Create;
    Try
      a.CommaText :='a,b,c,d,e,f,g';
      RadioGroup1.Items :=a;
    finally
      a.Free;
    end;
    end;
      

  6.   

    CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText CommaText
    ==========================================
    你是要这个吗?