0

次のように、oldList 内の特定の要素を選択してから、新しい要素を作成したいと考えています。

例#1: 奇数を取得
oldList = {1,2,3,4,5,6,7,8}
newList = {1,3,5,7}

例 2: 文字列を取得
する oldList = {1,"Tiger",{1,2,3}
newList = {"Tiger"}

例 1 のスクリプトを作成します。

set oldList to {1, 2, 3, 4, 5, 6}  

set newList to {}  
repeat with theItem in oldList  
    if theItem mod 2 = 1 then  
        copy theItem to end of newList  
    end if  
end repeat

newList は {1,3,5} のはずですが、実際には {oldList の項目 1,oldList の項目 2,,oldList の項目 3} です。私の質問は、この問題を解決する方法です。

この特定の例に関しては、簡単な解決策は、copy ステートメントを次のように変更することです。

copy theItem as integer to end of newList 

しかし、私はより一般的な解決策を探しています。代わりに、古いリストの要素のクラスを検討するのは面倒です。ありがとう!

4

1 に答える 1

0

AppleScript で繰り返しループがどのように機能するかについて詳しく読む必要があります。

set oldList to {1, 2, 3, 4, 5, 6}

set newList to {}
repeat with theItem in oldList
    set theItem to contents of theItem
    if theItem mod 2 = 1 then
        copy theItem to end of newList
    end if
end repeat
于 2013-06-17T19:03:14.473 に答える