Delphi read text file first if integers are in a text line

Viewed 115

I would like to only read a certain line from a text file if only numbers were used in this line and this content consists of a maximum of 5 numbers.

How can I write this in my if statement.

1 Answers

As already mentioned in comments, you cannot know what a thing is before you look at it.

In other words, if you want to continue only if the line is exactly five “numbers”, then you must read the line and attempt to convert it to exactly five “numbers”.

If that doesn’t succeed then you just ignore it all and continue looking for the next line to see if it matches.

If it does succeed then you have found a matching line and all is good.

The general rule of action is, then:

  • read a line
  • attempt to convert it to what you want
  • react to the success or failure of the conversion
Related