I’ve got an odd problem. I have a text file that is a listing (much like a directory listing). The list contains 3 columns of data separated by a variable number of spaces.
I can read the input lines fine using “read using delimiters {ascii character 10}” but when I ask for “words of” the first item in the list, it reads the @ sign as a separate word, the / as a word separator (meaning it disappears from the result) and the words with the - as one word. HUH? I’ve tried “considering/ignoring punctuation” without success.
Here’s the code:
set theFile to "Brain:Users:nitewing:dtext.txt" as alias
set theText to getFromFile(theFile)
set AppleScript's text item delimiters to "*" -- let's peek at what we have
--first record
set myitem to contents of item 1 of theText
display dialog (words of myitem) as text
--last record
set myitem to contents of item 1 of reverse of theText
display dialog (words of myitem) as text
to getFromFile(theFile)
try
-- Does the file exist?
open for access (theFile as alias)
copy the result to theFile_ID
on error
display dialog "Can't open the input file."
end try
-- Get the file length
get eof theFile_ID
copy the result to theFile_eof
-- get our data
try
read theFile_ID as string using delimiter {ASCII character 10}
copy the result to theFileinput
--display dialog "Got " & (theFileinput as text)
on error
display dialog "Can't read from file " & theFilename
end try
--close the file
close access theFile_ID
return theFileinput
end getFromFile
And here’s a sample of the file:
zope-zopetree<variable number of spaces>@1.3<variable number of spaces>zope/zope-zopetree
zope-zopezen<variable number of spaces>@0.5<variable number of spaces>zope/zope-zopezen
As you can see, there are a variable number of spaces between items, so I figured using “words of” would help dump the extra spaces. In order to keep processing time down, I need a FAST solution: The file is about 200k and if I have to go through it character by character it will take too long for my purposes.