Importing text file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Importing text file
Setup -
Mac OS X 10.5.4
Revolution Studio 2.9.0
Something strange is happening when I open a text file (saved as Windows TXT) and put the text of the file into a field (set to use Courier 12pt). The text gets placed okay, but there is a space in between each letter of each word. Very bizarre behavior.
for example - "word" appears as "w o r d"
If I open the file using a regular text editor or MS Word the file looks fine and there are no spaces between the letters of each word.
Anyone have a clue why this is happening?
TIA
Mac OS X 10.5.4
Revolution Studio 2.9.0
Something strange is happening when I open a text file (saved as Windows TXT) and put the text of the file into a field (set to use Courier 12pt). The text gets placed okay, but there is a space in between each letter of each word. Very bizarre behavior.
for example - "word" appears as "w o r d"
If I open the file using a regular text editor or MS Word the file looks fine and there are no spaces between the letters of each word.
Anyone have a clue why this is happening?
TIA
Hi NateCS,
Probably, you hav a unicode file. After reading the data, you may need to encode it and handle it as unicode rather than raw text. Try something like this:
Best,
Mark
Probably, you hav a unicode file. After reading the data, you may need to encode it and handle it as unicode rather than raw text. Try something like this:
Code: Select all
open file myFile for binary read
read from file myFile until EOF
close file myFile
put uniencode(it,"UTF8") into myUnicode
set the unicodeText of fld 1 to myUnicode
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Thanks Mark
That did help in that it did get rid of some extra characters, but the extra spaces remain. Very strange issue. I have tried different encodings and most of them show the added spaces except the Unicode 5 (Little Endian). However, even with that selected the "put" command still adds the spaces.
Any other thoughts?
Any other thoughts?
That did it.
BvG - your suggestion worked.
Thanks.
Thanks.
Found another cool method
In searching for batch text conversion on the Macintosh I found that you can use the textutil utility, inlcuded in Mac OSX 10.4 or better, for converting text from one format to another.
The terminal string I used, which worked great and was tons quicker, was:
find . -name *.txt -exec textutil -convert txt '{}' \;
Just open Terminal, navigate to the directory where you text files exist, and then run this line of code.
Worked like a champ and I did not have to use the "MyUnicode" trick above.
Hopefully this will help others down the line.
Cheers.
Macs Rule!!!
The terminal string I used, which worked great and was tons quicker, was:
find . -name *.txt -exec textutil -convert txt '{}' \;
Just open Terminal, navigate to the directory where you text files exist, and then run this line of code.
Worked like a champ and I did not have to use the "MyUnicode" trick above.
Hopefully this will help others down the line.
Cheers.
Macs Rule!!!