How to delete the line in memo according to the amounts of Numbers in Delphi?

Asked

Viewed 188 times

-2

Good Night, I have a memo that takes several strings and in many lines, I want to delete the lines that contain less or more than seven(7) numbers ,leaving only the lines that have exactly seven(7) numbers I’m trying with a code only that every Memo is erased.

var
cont, N: Integer;
begin
cont:= 0;
N := Length(GetStrNumber(Memo2.Lines.Strings[cont])); //N = quantidade de 
//números na linha no Memo

while (cont <= Memo2.Lines.Count  - 1)  do
if N <> 7 then  //Se N é diferente de 7 então apagar a linha

begin
Memo2.Lines.Delete(cont)
end

else
Inc(cont);

1 answer

1

The N you are using to validate this out of the loop that makes the interaction. Try it like this:

procedure ApagaLinhas;
var
cont, N: Integer;
begin
  cont:= 0;

  while (cont <= Memo1.Lines.Count  - 1)  do
  begin
    N := Length(GetStrNumber(Memo1.Lines.Strings[cont])); //N = quantidade de
    //números na linha no Memo
    if N <> 7 then  //Se N é diferente de 7 então apagar a linha
    begin
      Memo1.Lines.Delete(cont)
    end else
    begin
      Inc(cont);
    end;
  end;
end;

Browser other questions tagged

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