Odd behavior of read from file

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
Fishman60
Posts: 2
Joined: Mon Dec 07, 2009 4:00 am

Odd behavior of read from file

Post by Fishman60 » Mon Dec 07, 2009 4:06 am

I use the following statement to read a line from a text file

read from file myFileName for 1 line

It reads just fine, except that the return has spaces interspersed in the text. For example, the following:

Here is some text!

gets read as

H e r e i s s o m e t e x t !

Even the spaces between the words get extra spaces added.
Has anyone else experienced this? Does anyone knwo how to prevent this?

Thanks!

Scott

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

Re: Odd behavior of read from file

Post by FourthWorld » Mon Dec 07, 2009 4:20 am

Is the text in the file encoded in UTF-16?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Odd behavior of read from file

Post by sturgis » Mon Dec 07, 2009 4:29 am

Can you post your code?

Does the following put the line correctly into your message box? After changing file path of course.

Code: Select all

on mouseUp
   open file "~/Desktop/stuff.rtf" for read
   read from file "~/Desktop/stuff.rtf" for 1 line
   close file "~/Desktop/stuff.rtf"
   put it
end mouseUp

Fishman60
Posts: 2
Joined: Mon Dec 07, 2009 4:00 am

Re: Odd behavior of read from file

Post by Fishman60 » Mon Dec 07, 2009 12:42 pm

Regarding the file encoding, it is a comma separated value file (.csv) and I don't know the encoding. How would I figure out what encoding it had?

** I've done a little research and it seems that to determine the encoding, you have to look at the first two bytes of the file. I will try to do some more research on this. There were two odd characters in the first line of the file, so I'm suspecting that the encoding might be the issue. I'll keep you posted (so to speak!)**

** I tried the code on some different files with no unexpected results, so I'm assuming it is an encoding issue. I'm not sure how to handle that issue though for this particular file.**

Regarding the code, the code you list is pretty much what I am using (although I don't close the file before doing the put. I am going to continue to read all the lines in the file (and dealing with each line individually).

Thanks,
Scott

Post Reply