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: Ehsan Saffari <email@hidden>
- Date: Sat, 9 Jun 2001 02:47:00 -0600
On 08/06/2001 14:00, Ricardo Montiel <email@hidden> wrote:
>
on Wed, 6 Jun 2001 22:54:27, Ehsan Saffari at <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.
>
>
>
Hi Ehsan,
>
>
Yes, it is possible... once you apply an old trick. Here is the code:
>
>
>
----- Begin Script ----------------------------------------
>
>
set EhsanList to {{"aa", "bb", "cc"}, {"dd", "ee", "ff"}}
>
>
try
>
EhsanList as date
>
on error message
>
set EhsanList to text 14 thru -16 of message
>
end try
>
>
set EhsanList to my cambiarTexto(EhsanList, "}, {", return & return)
>
set EhsanList to my cambiarTexto(EhsanList, ", ", return)
>
>
EhsanList
>
>
on cambiarTexto(xText, xFind, xChange)
>
set oldDelims to AppleScript's text item delimiters
>
set AppleScript's text item delimiters to xFind
>
set xText to text items of xText
>
set AppleScript's text item delimiters to xChange
>
set xText to (xText as text)
>
set AppleScript's text item delimiters to oldDelims
>
return xText
>
end cambiarTexto
>
>
----- End Script ------------------------------------------
>
>
>
HTH
>
>
--
>
Saludos (Regards)
>
Ricardo Montiel
>
Buenos Aires - Argentina
>
>
PS: Please cc me, as I am in digest mode.
Hi Ricardo
That old trick, well done! There is only the minor point that each item
of each list ends up in quotes (error in my original post), but easily
fixed:
----- Begin Script ----------------------------------------
set x to {{"aa", "bb", "cc"}, {"dd", "ee", "ff"}}
try
x as date
on error message
set x to text 14 thru -16 of message
end try
set x to my cambiarTexto(x, "\", \"", return)
set x to my cambiarTexto(x, "\"}, {\"", return & return)
set x to text 2 thru -2 of x
on cambiarTexto(xText, xFind, xChange)
try
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to xFind
set xText to text items of xText
set AppleScript's text item delimiters to xChange
set xText to (xText as text)
set AppleScript's text item delimiters to oldDelims
return xText
on error
set AppleScript's text item delimiters to oldDelims
end try
end cambiarTexto
----- End Script ----------------------------------------
done with no repeat loops after all!
cheers
ehsan