Re: Converting a nested list to return delimited string with TIDs
Re: Converting a nested list to return delimited string with TIDs
- Subject: Re: Converting a nested list to return delimited string with TIDs
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 06 Jun 2001 23:00:42 -0700
On 6/6/01 9:54 PM, "Ehsan Saffari" <email@hidden> wrote:
>
I have a nested list:
>
>
{{"aa","bb","cc"},{"dd","ee","ff"}}
>
>
and I want to convert it to:
>
"aa"
>
"bb"
>
"cc"
>
>
"dd"
>
"ee"
>
"ff"
>
>
is this possible with TIDs? I've already done this with a repeat loop,
>
but can't figure out if TIDS can be applied to a list.
>
Applying TIDs in the ordinary way will turn any list, including complex
nested ones, into a single string. That's what 'text item delimiters' are
for, to delimit items of a continuous string. E.g.:
set n to {{"aa", "bb", "cc"}, {"dd", "ee", "ff"}}
set AppleScript's text item delimiters to {return}
set n to n as string
set AppleScript's text item delimiters to {""}
n
-->
"aa
bb
cc
dd
ee
ff"
To get what you want - separate strings on separate lines -- is not, I
think, possible within AppleScript itself. That puts the "lines" out of the
domain of normal AppleScript, since the return character is also a string,
so concatenating it to any of the other strings is going to make it all into
one string as above. I'm very curious as to how you got that AppleScript
result in a repeat loop, if that's what you meant. Can you demonstrate?
But in a scriptable text editor, where the quotes ( " ) are actually \" in
AppleScript, it can be done by TIDs:
set AppleScript's text item delimiters to {"\"" & return & "\""}
set n to {{"aa", "bb", "cc"}, {"dd", "ee", "ff"}}
set n to "\"" & n & "\""
set AppleScript's text item delimiters to {""}
n
-->
"\"aa\"
\"bb\"
\"cc\"
\"dd\"
\"ee\"
\"ff\""
which will show up in any text application just as you want:
"aa"
"bb"
"cc"
"dd"
"ee"
"ff"
--
Paul Berkowitz