determining a plain text file

Bill Marriott wjm at wjm.org
Sun Jul 9 22:37:53 EDT 2006


How about this idea:

put url "file:{yourfile}" into oneFile
put replacetext (oneFile,"[^\x20-\x7E\n\r\t]","") into twoFile
if length(oneFile) = length(twoFile) then put "It's a plain text file."

Basically it deletes anything that is not a tab, return, linefeed, or 
between space and tilde. If it's a pure text file it shouldn't contain any 
other characters, and the length of the two variables should be the same. 
(If I missed any characters you want to consider ASCII you can add them to 
the regex.)

Saves yourself the trouble of scanning each character one-by-one with 
chartonum.

Dan Shafer wrote...
> To be sure the file you're dealing with has only ASCII text characters in
> it, you'd need to read it into some variable and then use chartonum to see
> if any character in the file has an ASCII value higher than 128 (or 
> whatever
> you decide to define as the upper boundary of ASCII). 






More information about the use-livecode mailing list