I have a text file that has, on any given row, data that are expressed both in text format and in numeric format. Something like this:
Dog 5 4 7
How do I write a file reading routine in Delphi that reads this row and assigns the read values into the correct variables ("Dog" into a string variable and "5", "4" and "7" into real or integer variables)?
You can use
SplitString
fromStrUtils
to split the string into pieces. And then useStrToInt
to convert to integer.And obviously substitute
StrToFloat
if you have floating point values.You can use
File of TRecord
, with TRecord. For example:And simple procedure:
Take TJclStringList from Jedi Code Library.
On 1st step you take one list and do .LoadFromFile to split the file to rows. On second step you iterated through those rows and set secondary stringlist by those lines with space as delimiter. Then you iterate through secondary string list and do what u want.
Like that