Question: How to import CSV (comma delimited) text file with embedded strings in some fields?

I am exploring the idea of porting some of my functions to Maple from Mathematica. But I just found a big problem in importing comma delimited data that contains a string within a string. This is not a problem being imported in Mathematica, but I need help to do same thing in Maple.

I tried ImportMatrix (as suggested in https://www.mapleprimes.com/questions/221509-How-To-Read-Lines-From-File-With-Quoted-Strings and also tried Import then convert and in both cases Maple does not read the full string in the field. I will show simple example

This file, called data.txt

1,2,3,"x+y, algorithm=["123"]","OK",5

It has 6 fields (since comma seperated.

But when importing it, Maple reads the 4th field above as "x+y, algorithm=[" and drops the rest 123"]"

Here is the code

#currentdir("C:\\bug"); #change as needed
data:=ImportMatrix("data.txt", source=csv);
print(data(4));
print(data(5));

This is the output

I also tried

data := Import("data.txt",format="CSV");
data := convert(data,Matrix):
print(data(4));
print(data(5));

Same output as above.

Compare the output in Mathematica. Using the same file as input. It automatically escapes the embedded strings and reads the full field OK

SetDirectory[NotebookDirectory[]];
data = First@Import["data.txt", "Table", "FieldSeparators" -> {","}, "Numeric" -> True]

               {1, 2, 3, "x+y, algorithm=[\"123\"]", "OK", 5}

data[[4]]

              "x+y, algorithm=[\"123\"]"

What would be the right way in Maple to import such files without losing part of the field?

The file has mixed strings and non strings, just like this example shows, and each file fields are seperated by comma, but I need to be able to read fields that can contain embedded strings in them automatically.

I am using Maple 2020. I think I might have to forget about import and try to do it using lower level code using scanf, or may be there is better method using Filetools package? but thought to check first if I am overlooking some option.

Please Wait...