On the first record I get 8 fields and then it goes to 7 (which is right).
As I surmised: not a problem of code but of data.
You're reading an UTF8 BOM along with the first record which gets taken as the first field (after all, it ends in a '['), so all the rest are off-by one and when you were trying to read the 6th word, it was, from its point of view correctly, returning "K2".
Don't save files with UTF8 BOM, it's an absurd convention invented by Microsoft to avoid having to check if a file really contains UTF-8 data.
If you can't avoid having the files with the UTF-8 BOM, you can load them first in a TMemo and assign the Memo.Lines tio the listbox items.
One other, unimportant, thing: why are you loading the files by hand (with assing, readln, etc.) instead of using ListBox.Items.LoadFromFile()?
ETA By the way, the UTF-8 BOM is not:
#$EF + #$BB + #$FF
but
#$EF + #$BB + #$BF
Let's be precise with these kind of things
UTF8 BOM <--- No Idea what that is.
The data is extracted from a file of 7.9 million records. And I guess the 7.9 million records are UTF8 BOM.
"One other, unimportant, thing: why are you loading the files by hand (with assing, readln, etc.) instead of using
ListBox.Items.LoadFromFile()?"
Well basically I'm reading a text file into a listbox.
1. I know how to do it this.
2. Habit. Maybe Bad Habit.
"If you can't avoid having the files with the UTF-8 BOM, you can load them first in a TMemo and assign the Memo.Lines tio the listbox items."
Don't understand the "and assign the Memo.Lines to the listbox items.
Listbox1.Items.Add(Line) := Memo.Lines ???
There are two data files for the program. One is 38,000 records and the other is about 16,000. I guess both are UTF-8 BOM.
If I load the 38,000 records into a Memo1 and then load them into a listbox and the save them to a text file.
Will that get rid of the UTF-8 BOM in the text file?
Well I can't avoid it as the data is extracted from a 7.9 million data set.
Not against pre-processing the file into ASCII if there is a way.