iOS Question LoadCSV : out of bounds

voxel

Member
Licensed User
Hi,
I use this code with B4A I don't have a problem, but with B4I I get this error when there is too much data. I don't understand, should I recode the loading of a CSV file and not use LoadCSV ?

Error occurred on line: 2791 (B4XMainPage)
-[__NSCFString substringWithRange:]: Range {5497, 18446744073709546118} out of bounds; string length 70968



B4X:
Dim su As StringUtils
Dim list As List

list.Initialize
list=su.LoadCSV(File.DirLibrary, "api.csv",";")

Thanks for your help.
 

emexes

Expert
Licensed User
18446744073709546118 looks like -5498 misinterpreted as a 64 bit unsigned.

But if the problem is occurring within the LoadCSV call, then it's hard to see how your code would cause that eror.

What is the length of the file api.csv?

Is it pure ASCII, or does it contain some high-bit characters eg UTF-8?
 
Upvote 0

emexes

Expert
Licensed User
Also, check the line termination characters:

are they consistently CR, CR+LF, or LF?

is the last line terminated?
 
Upvote 0

emexes

Expert
Licensed User
but with B4I I get this error when there is too much data

if m lines read ok and n lines don't,
then use a binary search to locate which line number m+1 .. n the problem begins at,
then have a very close look at that line
 
Upvote 0

voxel

Member
Licensed User
I may have found a difference in the file, the 1st column is empty on 2 lines, is this the reason for the LoadCSV crash?

"7.5";"2023-03-22T08:48:00Z"
"7.4";"2023-03-21T13:18:00Z"
"7.5";"2023-03-21T13:18:00Z"
"7.6";"2023-03-20T13:45:00Z"
"8.0";"2023-03-20T13:45:00Z"
"7.6";"2023-03-17T10:30:00Z"
"";"2023-03-17T10:30:00Z"
"";"2023-03-16T12:21:00Z"
"7.6";"2023-03-16T12:21:00Z"
"7.4";"2023-03-15T11:30:00Z"
"7.5";"2023-03-15T11:30:00Z"
"7.6";"2023-03-14T12:42:00Z"
 
Upvote 0

emexes

Expert
Licensed User
the 1st column is empty on 2 lines, is this the reason for the LoadCSV crash?


"8.0";"2023-03-20T13:45:00Z"
"7.6";"2023-03-17T10:30:00Z"
"";"2023-03-17T10:30:00Z"
"";"2023-03-16T12:21:00Z"
"7.6";"2023-03-16T12:21:00Z"
"7.4";"2023-03-15T11:30:00Z"

You're the one already set up to answer that good question: remove those two lines from your test file; run your app; let us know. šŸ»
 
Upvote 0

voxel

Member
Licensed User
You're the one already set up to answer that good question: remove those two lines from your test file; run your app; let us know. šŸ»
It is difficult to modify this file because this data comes directly from an API. I no longer have a problem using CSV Parser. I think there is a bug on LoadCSV on B4i because on B4a, I have the same code and I have no problem.
 
Upvote 0
Top