Importing text file

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
NateC512
Posts: 6
Joined: Mon Apr 10, 2006 12:02 pm

Importing text file

Post by NateC512 » Thu Aug 14, 2008 10:01 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Aug 14, 2008 11:23 pm

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:

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
Best,

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

NateC512
Posts: 6
Joined: Mon Apr 10, 2006 12:02 pm

Thanks Mark

Post by NateC512 » Fri Aug 15, 2008 3:25 pm

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?

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Fri Aug 15, 2008 3:45 pm

try "Unicode" (utf-16) instead of UTF8.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

NateC512
Posts: 6
Joined: Mon Apr 10, 2006 12:02 pm

That did it.

Post by NateC512 » Fri Aug 15, 2008 4:41 pm

BvG - your suggestion worked.

Thanks.

NateC512
Posts: 6
Joined: Mon Apr 10, 2006 12:02 pm

Found another cool method

Post by NateC512 » Tue Aug 26, 2008 9:35 pm

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!!!

Post Reply