Page 1 of 1

How to read .csv?

Posted: Thu Mar 17, 2016 5:41 pm
by croivo
Hello,
I'm trying to read .csv file exported from Excel.
Here is a piece of code:

Code: Select all

   answer file "Select a file you want to load" with type "Csv Files|csv|CSV"
   if it is not empty then
      put it into tfilename
      put url ("binfile:" & tFilename) into tempVar
However, the problem is that it won't read all characters. For example, if there are symbols like č ć ž š đ, they won't show up. Instead, some other symbols will show.
I tried several functions, none of them seems to be working.

Re: How to read .csv?

Posted: Thu Mar 17, 2016 5:50 pm
by dunbarx
Hi.

Confirmed here in v.6.7.9. I get underScores for all those example chars. Mac OS 10.9.

CSV files are to be avoided at all costs, though this has nothing to do with the issue. Or does it?

Craig Newman

EDIT:

I also get underscores with .txt.

Re: How to read .csv?

Posted: Thu Mar 17, 2016 6:07 pm
by croivo
The thing is that I can read .txt with all kind of symbols without any problem, but can't .csv.

This is the code that i'm using:

Code: Select all

   if it is not empty then
      put it into tfilename
      put url ("binfile:" & tFilename) into tempVar
      
      put uniencode(tempVar, "utf8") into tempVar2
      set the unicodeText of field "myTextField" of stack "internalSettings" to tempVar2
The data I get in field "myTextField" is full of weird symbols when .csv is loaded. But when .txt, everything is ok.

Re: How to read .csv?

Posted: Thu Mar 17, 2016 6:14 pm
by FourthWorld
croivo wrote:The data I get in field "myTextField" is full of weird symbols when .csv is loaded. But when .txt, everything is ok.
Whether the file name ends with ".csv" or ".txt" or ".tab" or ".whatever" shouldn't affect the content within the file.

You may want to reexamine the files' contents to determine the difference. My hunch is that different encoding is being used for each.

Re: How to read .csv?

Posted: Thu Mar 17, 2016 6:15 pm
by dunbarx
Someone with more experience with file types will likely chime in soon. Maybe it is a unicode issue?

Craig

Re: How to read .csv?

Posted: Thu Mar 17, 2016 10:42 pm
by croivo
Found a solution...

Just changed encoding type...

Code: Select all

put uniencode(tempVar, "iso-8859-1") into tempVar2
So, from utf8 to iso-8859-1.