START > APPLESCRIPT > Praktische Handler > Listen-Position ermitteln

Listen-Position ermitteln

Dieser AppleScript-Handler ermittelt die Position eines angegebenen Elementes in einer Liste.

-- BEISPIEL-AUFRUF:
set x to 15
set Liste to {1, 3, 5, 7, 9, 11, 13, 15, 17}
hohaGetListPos(x, Liste) --> ERGEBNIS: 8

-- :::::::::::::::::::::::::::::::::  hohabadu.de  :::::::::::::::::::::::::::::::::

on hohaGetListPos(search, TheList)
   set {oldASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "|"}
   set {tSearch, tTheList} to {"|" & (search as text) & "|", "|" & (TheList as text) & "|"}
   set pre to offset of tSearch in tTheList
   if pre is greater than 1 then
      set ListPOS to (count text items of (text 1 thru (pre - 1) of tTheList))
   else
      set ListPOS to pre
   end if
   set AppleScript's text item delimiters to oldASTID
   return ListPOS
end hohaGetListPos
 Im Scripteditor öffnen



Powered By CMSimple Design By NMuD Top