I can’t remember where or how I got text items with multiple delimiters before. For instance, ths:
set t to "abcdefgh"
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"c", "f"}
set l to text items of t
set AppleScript's text item delimiters to utid
l
--> {"ab", "defgh"}
would return this:
→ {“ab”, “de”, “gh”}
I think it might have been used with text items of some text editor, in a tell block. Anybody know how this happened?
I notice that each item in the delimiter has to be one character.
Just had a play and found a way to use a complete string or a whole word, Not sure how useful it would be, but you never know
set the_delim to characters of "the text I want to use "
set new_file_path to (path to desktop as Unicode text) & "Test.txt"
set t to read file new_file_path using delimiter the_delim
‘using delimiters’ is good for getting a flat list instead of a list of paragraphs in delimited text file. For instance, in this tab delimited text file:
you could get easily get every item of field 2. e.g.
set lf to ASCII character 10
set f to choose file
set l to read f using delimiter {tab, lf}
set c to count l
set field_items to {}
set field_index to 1
set field_count to 2
repeat with i from 1 to c by field_count
set this_item to item (i + (field_index - 1)) of l
set end of field_items to this_item
end repeat
field_items
Instead of getting every paragraph, repeating through that list, and getting the items from field 2, you can step through the flat list.
set t to "abcdefgh"
set AppleScript's text item delimiters to {"bc", "f"}
-->{"a", "defgh"}
if multiple items are defined, only the first (“bc”) is effective, all others are ignored,
but the delimiter can contain more than one character
¢ the other example with read using delimiter
set f to choose file --> assuming "abcdefgh"
set l to read f using delimiter {"cd", "f"}
--> {"ab","de","gh"}
In this case all items of the delimiter list can be used, but the delimiter can only be one character,
so only the first character ist effective, if there are more than one character