How to read .csv?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

How to read .csv?

Post by croivo » Thu Mar 17, 2016 5:41 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to read .csv?

Post by dunbarx » Thu Mar 17, 2016 5:50 pm

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.

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: How to read .csv?

Post by croivo » Thu Mar 17, 2016 6:07 pm

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to read .csv?

Post by FourthWorld » Thu Mar 17, 2016 6:14 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to read .csv?

Post by dunbarx » Thu Mar 17, 2016 6:15 pm

Someone with more experience with file types will likely chime in soon. Maybe it is a unicode issue?

Craig

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: How to read .csv?

Post by croivo » Thu Mar 17, 2016 10:42 pm

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.

Post Reply