Page 1 of 1
Odd behavior of read from file
Posted: Mon Dec 07, 2009 4:06 am
by Fishman60
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
Re: Odd behavior of read from file
Posted: Mon Dec 07, 2009 4:20 am
by FourthWorld
Is the text in the file encoded in UTF-16?
Re: Odd behavior of read from file
Posted: Mon Dec 07, 2009 4:29 am
by sturgis
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
Re: Odd behavior of read from file
Posted: Mon Dec 07, 2009 12:42 pm
by Fishman60
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