Question: How to read lines from file, with quoted strings?

After 3 hrs trying I give up.  I am a Maple newbie.

I need to read a plain text file, where each line contains 12 fields in it.

The fields are comma separated.  But some of the fields are quoted strings. Here is an example of one line below. I can read the line OK, as a string, using readline(), but I do not know how to split it correctly into 12 fields inside Maple once read, so I can access each field easily and make any changes I want.

The problem is that, once I read the line using readline(), it comes in as string. But it has string embeded in it allready, since the line in the file, allready has quoted string as fields.

Here is one line in file foo.txt

1,2,3,4,0.1,5,"int(x^2,x)","\frac{x^3}{3}",6,7,"(2*x + 1)^(3/2)/3","A"

Each line has the same number of fields. 12.  Now I do this:


And now current_line is

"1,2,3,4,0.1,5,"int(x^2,x)","\frac{x^3}{3}",6,7,"(2*x + 1)^(3/2)/3","A""

And here I am stuck. I tried StringTools[Split], I tried sscanf, tried readata, and nothing worked. For example, if I do


The result is

[1, 2, 3, 4, .1, 5, ""int(x^2,x)","\frac{x^3}{3}",6,7,"(2*x"]

The fields are


The problem is the embeded string. I am sure there is a Maple function to do this easily, I just can't find it.

What is the correct way to read these lines, and split them into a Matlab list (of lists) so I can access them easily inside Maple?

Using Maple 2016.2

Please Wait...