How to read text data (copied from an excel sheet) in Delphi?

489 views Asked by At

I need to read the following text in a file and store the values with field names. Its actually copied from am excel sheet:

A: B C D E (not TEXT based)

Field Description Length in bytes Count Total bytes

Identification 10 1 10

IX 4 1 4

Scan date time 8 1 8

Machine type 4 1 4

I stored it in a stringlist and I am unsure about what to do next. Can anyone please help? Thanks.

1

There are 1 answers

2
Nick Barnes On BEST ANSWER

First of all, I'd save it from Excel as a .csv, open it in Notepad, and copy it from there. The lack of (unambiguous) field delimiters in your current format makes it awkward to tokenise. When saving the .csv, pick a field delimiter which doesn't appear in any of your text fields, and leave the text delimiter blank.

With that done, just split each of your strings on the delimiter character, and do what you want with the pieces. Simplest way to do it is probably to set the string as the CommaText on a second TStringList.