234,4353,456,456,456,567,834,156,546155651,123131,1233213,54646,123,1321,313131,321,321321,332132,133123,123,132如何读到数组,请帮忙

解决方案 »

  1.   

    Function GetSubStrNum(aString:String;SepChar:String):integer;
    var
    i:Integer;
    StrLen:Integer;
    Num:Integer;
    begin
    StrLen:=Length(aString);
    Num:=0;
    For i:=1 to StrLen do
    If Copy(aString,i,1) = SepChar then
    Num:=Num+1;
    result:=Num;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
    i,strl:integer;
    sourcestr:string;
    Mystr:String;
    StrLen:Integer;
    SepCharPos:Integer;
    myarray:array[0..30] of integer;
    begin
        sourcestr:='234,4353,456,456,456,567,834,156,546155651,123131,1233213,54646,123,1321,313131,321,321321,332132,133123,123,132';
        strl:=GetSubStrNum(sourcestr,',');
        for i:=1 to strl do
        begin
            StrLen:=Length(sourcestr);
        SepCharPos:=Pos('\',sourcestr); //计算分割符在子串中的位置
        MyStr:=Copy(sourcestr,1,SepCharPos-1); //将分割符前所有字符放到mystr串中
        Delete(sourcestr,1,SepCharPos); //除去分割符和分割符前的子串
                myarray[i-1]:=strtoint(MyStr);
        end;
    end;
      

  2.   

    var
      I :Integer;
      S: string;
      A: array of Integer;
    begin
      S := '234,4353,456,456,456,567,834,156,546155651,123131,1233213,' +
        '54646,123,1321,313131,321,321321,332132,133123,123,132';
      with TStringList.Create do try
        Delimiter := ',';
        DelimitedText := StringReplace(S, ',', ',', [rfReplaceAll]);
        SetLength(A, Count);
        for I := 0 to Count - 1 do
          A[I] := StrToIntDef(Strings[I], 0);
      finally
        Free;
      end;
    end;
      

  3.   

    给你个完整的:function SplitString(const source,ch:string):tstringlist;
    var
     temp:string;
     i:integer;
    begin result:=tstringlist.Create;
     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;
      

  4.   

    回复人: Linux2001(恋人不如自恋) ( ) 信誉:101  2004-07-08 10:29:00  得分: 0  
     
     
       我服了你了,数据都完整的知道了,如何读入数组还不知道
      
     
    ***************
    说得也是,都不知道楼主怎么混的!!