In a current project, I have to read a text file (in fact, many) that hold data as csv container files.
As an example, I use the following code to fill the ListBox Heading:
First line of the csv file:
"Cover","Archive name","Size","Date added","Download"
Xojo code:
[code] // Fill the ListBox Heading
For HeadIdx = 1 To HeadCnt
// Get the correct value for this heading
HeadField = NthField(LibgenURL,",",HeadIdx)
TheField = Mid(HeadField,2,Len(HeadField)-2) // remove the two " (*)
// Fill the heading
LB.Heading(0) = TheField
// To avoid 1, Infinite Loop
If UserCancelled Then Exit
Next
[/code]
In reading the documentation, I happen to read:
NOTE: Using NthField in a loop to extract fields from a string is inefficient. You should use Split for this purpose.
As a nice young boy, I wanted to follow the documentation advice. What a crazy idea did I had ! In line noted (*), you can understand how I remove the leading and ending quotes for each field. Using Split and Join seems to me a bad idea in this respect because I have to remove them in some way.
My new code looks like:
HeadStr() = URL.Split(",")
LB.Heading(-1) = Join(HeadStr,chr(9))
The new new code have two lines vs the previous code (6 lines), or just a one liner:
LB.Heading(-1) = Join(URL.Split(","),chr(9))
But that code do not remove the leading and ending quotes from the text stored in a csv file.
So, excepted if we have a solution, I will come back to my ineficient code (that works nice for hundred lines).