Placing values of a memo inside an array

Asked

Viewed 709 times

1

I have the following component Memo with the texts:

200:80
177:3306

I need to put this text inside a array, for example, based on the first line, the text 200 (would be array[1]) and the countryside 80 (would be array[2]). Remembering that I need to use as a delimiter the : (two points), and in the sequence traverse that same and show in a ShowMessage.

I can’t do it at all.

1 answer

1


You can use the function ExtractStrings

Var
 Numeros: TStringList;
 Numero: string;
begin
 Numeros := TStringList.Create;

 Memo1.Clear;
 Memo1.Lines.Add('200:80');
 Memo1.Lines.Add('177:3306');

 try
   ExtractStrings([':'], [], pchar(Memo1.Text), Numeros);

   for Numero in Numeros do begin
     Showmessage(Numero);
   end;

 finally
   Numeros.Free;
 end;
  • @user7605 ShowMessage(Numeros.Text);?

  • sorry, I said wrong. Memo has several lines, it is showing only the first in the showmessage, understand ?

  • @user7605 ShowMessage(Numeros[0]); will show the first item of array, ShowMessage(Numeros.Text); will show all items contained in this array. The Memo1.Lines.Add(...) is just one example.

  • @user7605 In the example above, to show the value 80, you do: ShowMessage(Numeros[1]); and so on...

  • thanks for the patience. Is there a way if I put it like this: Showmessage(Numbers[0]); it show all of that array at once ? Like, show one, I give OK, in sequence shows another and so on ?

  • @user7605 I updated the answer, see if this is it.

  • Perfect friend, thank you!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.