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
Odd behavior of read from file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Odd behavior of read from file
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Odd behavior of read from file
Can you post your code?
Does the following put the line correctly into your message box? After changing file path of course.
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
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
** 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