Text item delimters list?

I just noticed today that “Applescript’s text item delimiters” is actually a list of one item. Does anyone know why? I thought maybe you could have additional items in the list and parse a text string with multiple characters. You can indeed set the list to multiple items but Applescript only uses the first item in the list. This borders on the obscure but there must be a reason someone bothered to make this a list rather than a string like “pi”, “tab” or “return”.

It’s a list in case multiple delimiters should ever be implemented in the future. It’s been like that for several years, but multiple delimiters have yet to appear in vanilla AppleScript…

It’s sometimes tempting to do cute tricks like using the list as a stack for old delimiters, etc., but it’s best not to in case the situation should ever change. It does however seem to be OK to set delimiter(s) without the list.

Thanks, that makes sense. As for using the list as a stack, I get myself in enough trouble managing one delimiter. I constantly forget to restore the delimiter in the event of an error. I can’t imagine the mess I could create with a stack of delimiters!

I’ve got a question that’s kind of related to this. I have a file that I want to parse information off of each line. I tried reading the file with delimiter return, but that gave me a 1-item list with all the text in the one item. I then tried reaing with dilimiter "
" and it worked like it should. Why doesn’t the keyword return work?

Script Editor 2 uses line feeds (ASCII character 10) instead of carriage returns (ASCII character 13) to end lines. Maybe the lines in your file are line-feed terminated too.

If the file’s not too huge for your computer’s memory, it’s faster (and more reliable nowadays) to do something like this:

set theText to (read file myFile from 1 as text)
set theLines to theText's paragraphs

This is straying from the original thread but …

Do I still need to worry about a 32k limit when reading files?

I was forgetting about that. Testing with Jaguar, I’ve no problem reading files up to at least 2.1MB. But trying to extract their paragraphs or to extract their lines using text item delimiters causes a stack overflow. (I know it’s not possible to extract more than about 4000 text items from a string on my system). My other machine is currently reading a 2.1MB file ‘using delimiter return’. The little ball’s been spinning for the past ten minutes… :wink:

It seems to be OK if you don’t try to get all the paragraphs at once:

set t to (read file "my2.1MBfile.txt" from 1 as text)
set p to t's paragraphs --> error

-- But:
count t's paragraphs --> OK
get t's last paragraph --> OK

I’m afraid I don’t know what the situation is with Panther or will be with Tiger.