Q&A

  • 배열에서 같은 데이타를 뺀 배열을 구하고 싶습니다
teststr:array[0..20] of string;

newstr:array[0..20] of string;



문자열배열 teststr에

{'111','222','333','111','444','222'}가 있을때

같은 데이타를 빼고

newstr에

{'111','222','333','444'}가 나올수 있게하려면

어떻게 코딩해야 할까요?

고수님의 도움 부탁드립니다

1  COMMENTS
  • Profile
    이명훈 2001.10.09 21:31
    참고해보세요.



    unit Unit1;



    interface



    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    StdCtrls;



    type

    TForm1 = class(TForm)

    Memo1: TMemo;

    Button1: TButton;

    Memo2: TMemo;

    procedure Button1Click(Sender: TObject);

    private

    { Private declarations }

    public

    { Public declarations }

    end;



    var

    Form1: TForm1;

    MyString: Array[1..6] of String=('111','222','333','111','444','222');

    MyNewString: Array[1..6] of String=(' ',' ',' ',' ',' ',' ');



    implementation



    {$R *.DFM}



    procedure TForm1.Button1Click(Sender: TObject);

    var

    I,J: Integer;

    InNya: Boolean;

    Count: Integer;

    begin

    Count:=1;

    For I:=1 to 6 do

    Begin

    InNya:=False;

    For J:=1 to 6 do

    IF MyString[I]=MyNewString[J] then InNya:=True;

    If Not InNya then

    Begin

    MyNewString[Count]:=MyString[I];

    Inc(Count);

    End;

    End;

    For I:=1 to Count do Memo2.Lines.Add(MyNewString[I]);

    end;



    end.





    만성 wrote:

    > teststr:array[0..20] of string;

    > newstr:array[0..20] of string;

    >

    > 문자열배열 teststr에

    > {'111','222','333','111','444','222'}가 있을때

    > 같은 데이타를 빼고

    > newstr에

    > {'111','222','333','444'}가 나올수 있게하려면

    > 어떻게 코딩해야 할까요?

    > 고수님의 도움 부탁드립니다